11using System ;
22using System . Threading . Tasks ;
3+ using System . Runtime . CompilerServices ;
34using Newtonsoft . Json . Linq ;
45
6+ [ assembly: InternalsVisibleTo ( "Kuzzle.Tests" ) ]
7+
58namespace KuzzleSdk . API . Controllers {
69 /// <summary>
710 /// Implements the "auth" Kuzzle API controller
811 /// </summary>
912 public sealed class AuthController : BaseController {
10- internal AuthController ( Kuzzle k ) : base ( k ) { }
13+ internal AuthController ( IKuzzleApi api ) : base ( api ) { }
1114
1215 /// <summary>
1316 /// Checks the validity of an authentication token.
1417 /// </summary>
1518 public async Task < JObject > CheckTokenAsync ( string token ) {
16- string jwt = kuzzle . Jwt ;
17- kuzzle . Jwt = null ;
19+ string jwt = api . Jwt ;
20+ api . Jwt = null ;
1821 Response response ;
1922
2023 try {
21- response = await kuzzle . QueryAsync ( new JObject {
24+ response = await api . QueryAsync ( new JObject {
2225 { "controller" , "auth" } ,
2326 { "action" , "checkToken" } ,
2427 {
@@ -29,7 +32,7 @@ public async Task<JObject> CheckTokenAsync(string token) {
2932 }
3033 } ) ;
3134 } finally {
32- kuzzle . Jwt = jwt ;
35+ api . Jwt = jwt ;
3336 }
3437
3538 return ( JObject ) response . Result ;
@@ -41,7 +44,7 @@ public async Task<JObject> CheckTokenAsync(string token) {
4144 public async Task < JObject > CreateMyCredentialsAsync (
4245 string strategy ,
4346 JObject credentials ) {
44- Response response = await kuzzle . QueryAsync ( new JObject {
47+ Response response = await api . QueryAsync ( new JObject {
4548 { "controller" , "auth" } ,
4649 { "action" , "checkToken" } ,
4750 { "body" , credentials } ,
@@ -56,7 +59,7 @@ public async Task<JObject> CreateMyCredentialsAsync(
5659 /// specified authentication strategy.
5760 /// </summary>
5861 public async Task < bool > CredentialsExistAsync ( string strategy ) {
59- Response response = await kuzzle . QueryAsync ( new JObject {
62+ Response response = await api . QueryAsync ( new JObject {
6063 { "controller" , "auth" } ,
6164 { "action" , "credentialsExist" } ,
6265 { "strategy" , strategy }
@@ -74,7 +77,7 @@ public async Task<bool> CredentialsExistAsync(string strategy) {
7477 /// the deleted credentials.
7578 /// </summary>
7679 public async Task DeleteMyCredentialsAsync ( string strategy ) {
77- await kuzzle . QueryAsync ( new JObject {
80+ await api . QueryAsync ( new JObject {
7881 { "controller" , "auth" } ,
7982 { "action" , "deleteMyCredentials" } ,
8083 { "strategy" , strategy }
@@ -85,7 +88,7 @@ await kuzzle.QueryAsync(new JObject {
8588 /// Returns information about the currently logged in user.
8689 /// </summary>
8790 public async Task < JObject > GetCurrentUserAsync ( ) {
88- Response response = await kuzzle . QueryAsync ( new JObject {
91+ Response response = await api . QueryAsync ( new JObject {
8992 { "controller" , "auth" } ,
9093 { "action" , "getCurrentUser" }
9194 } ) ;
@@ -99,7 +102,7 @@ public async Task<JObject> GetCurrentUserAsync() {
99102 /// should never include any sensitive information.
100103 /// </summary>
101104 public async Task < JObject > GetMyCredentialsAsync ( string strategy ) {
102- Response response = await kuzzle . QueryAsync ( new JObject {
105+ Response response = await api . QueryAsync ( new JObject {
103106 { "controller" , "auth" } ,
104107 { "action" , "getMyCredentials" } ,
105108 { "strategy" , strategy }
@@ -113,7 +116,7 @@ public async Task<JObject> GetMyCredentialsAsync(string strategy) {
113116 /// current user.
114117 /// </summary>
115118 public async Task < JArray > GetMyRightsAsync ( ) {
116- Response response = await kuzzle . QueryAsync ( new JObject {
119+ Response response = await api . QueryAsync ( new JObject {
117120 { "controller" , "auth" } ,
118121 { "action" , "getMyRights" }
119122 } ) ;
@@ -125,7 +128,7 @@ public async Task<JArray> GetMyRightsAsync() {
125128 /// Gets the exhaustive list of registered authentication strategies.
126129 /// </summary>
127130 public async Task < JArray > GetStrategiesAsync ( ) {
128- Response response = await kuzzle . QueryAsync ( new JObject {
131+ Response response = await api . QueryAsync ( new JObject {
129132 { "controller" , "auth" } ,
130133 { "action" , "getStrategies" }
131134 } ) ;
@@ -138,24 +141,24 @@ public async Task<JArray> GetStrategiesAsync() {
138141 /// </summary>
139142 public async Task < JObject > LoginAsync (
140143 string strategy , JObject credentials , string expiresIn = null ) {
141- string jwt = kuzzle . Jwt ;
142- kuzzle . Jwt = null ;
144+ string jwt = api . Jwt ;
145+ api . Jwt = null ;
143146 Response response ;
144147
145148 try {
146- response = await kuzzle . QueryAsync ( new JObject {
149+ response = await api . QueryAsync ( new JObject {
147150 { "controller" , "auth" } ,
148151 { "action" , "login" } ,
149152 { "strategy" , strategy } ,
150153 { "body" , credentials } ,
151154 { "expiresIn" , expiresIn }
152155 } ) ;
153156 } catch ( Exception ) {
154- kuzzle . Jwt = jwt ;
157+ api . Jwt = jwt ;
155158 throw ;
156159 }
157160
158- kuzzle . Jwt = ( string ) response . Result [ "jwt" ] ;
161+ api . Jwt = ( string ) response . Result [ "jwt" ] ;
159162
160163 return ( JObject ) response . Result ;
161164 }
@@ -165,7 +168,7 @@ public async Task<JObject> LoginAsync(
165168 /// If there were any, real-time subscriptions are cancelled.
166169 /// </summary>
167170 public async Task LogoutAsync ( ) {
168- await kuzzle . QueryAsync ( new JObject {
171+ await api . QueryAsync ( new JObject {
169172 { "controller" , "auth" } ,
170173 { "action" , "logout" }
171174 } ) ;
@@ -175,13 +178,13 @@ await kuzzle.QueryAsync(new JObject {
175178 /// Refreshes an authentication token.
176179 /// </summary>
177180 public async Task < JObject > RefreshTokenAsync ( string expiresIn = null ) {
178- Response response = await kuzzle . QueryAsync ( new JObject {
181+ Response response = await api . QueryAsync ( new JObject {
179182 { "controller" , "auth" } ,
180183 { "action" , "login" } ,
181184 { "expiresIn" , expiresIn }
182185 } ) ;
183186
184- kuzzle . Jwt = ( string ) response . Result [ "jwt" ] ;
187+ api . Jwt = ( string ) response . Result [ "jwt" ] ;
185188
186189 return ( JObject ) response . Result ;
187190 }
@@ -192,7 +195,7 @@ public async Task<JObject> RefreshTokenAsync(string expiresIn = null) {
192195 public async Task < JObject > UpdateMyCredentialsAsync (
193196 string strategy ,
194197 JObject credentials ) {
195- Response response = await kuzzle . QueryAsync ( new JObject {
198+ Response response = await api . QueryAsync ( new JObject {
196199 { "controller" , "auth" } ,
197200 { "action" , "updateMyCredentials" } ,
198201 { "strategy" , strategy } ,
@@ -207,7 +210,7 @@ public async Task<JObject> UpdateMyCredentialsAsync(
207210 /// associated profiles cannot be updated)
208211 /// </summary>
209212 public async Task < JObject > UpdateSelfAsync ( JObject content ) {
210- Response response = await kuzzle . QueryAsync ( new JObject {
213+ Response response = await api . QueryAsync ( new JObject {
211214 { "controller" , "auth" } ,
212215 { "action" , "updateSelf" } ,
213216 { "body" , content }
@@ -224,7 +227,7 @@ public async Task<JObject> UpdateSelfAsync(JObject content) {
224227 public async Task < bool > ValidateMyCredentialsAsync (
225228 string strategy ,
226229 JObject credentials ) {
227- Response response = await kuzzle . QueryAsync ( new JObject {
230+ Response response = await api . QueryAsync ( new JObject {
228231 { "controller" , "auth" } ,
229232 { "action" , "validateMyCredentials" } ,
230233 { "body" , credentials } ,
0 commit comments