@@ -99,12 +99,22 @@ public bool SetUserPassword(CloudIdentity identity, string userId, string passwo
9999 {
100100 var user = GetUser ( identity , userId ) ;
101101
102+ return SetUserPassword ( identity , user , password ) ;
103+ }
104+
105+ public bool SetUserPassword ( CloudIdentity identity , User user , string password )
106+ {
107+ return SetUserPassword ( identity , user . Id , user . Username , password ) ;
108+ }
109+
110+ public bool SetUserPassword ( CloudIdentity identity , string userId , string username , string password )
111+ {
102112 var urlPath = string . Format ( "v2.0/users/{0}/OS-KSADM/credentials" , userId ) ;
103113 var request = new SetPasswordRequest
104- {
105- PasswordCredencial =
106- new PasswordCredencial { Username = user . Username , Password = password }
107- } ;
114+ {
115+ PasswordCredencial =
116+ new PasswordCredencial { Username = username , Password = password }
117+ } ;
108118 var response = ExecuteRESTRequest < PasswordCredencialResponse > ( identity , urlPath , HttpMethod . POST , request ) ;
109119
110120 if ( response == null || response . StatusCode != 201 || response . Data == null )
@@ -128,8 +138,18 @@ public UserCredential UpdateUserCredentials(CloudIdentity identity, string userI
128138 {
129139 var user = GetUser ( identity , userId ) ;
130140
141+ return UpdateUserCredentials ( identity , user , apiKey ) ;
142+ }
143+
144+ public UserCredential UpdateUserCredentials ( CloudIdentity identity , User user , string apiKey )
145+ {
146+ return UpdateUserCredentials ( identity , user . Id , user . Username , apiKey ) ;
147+ }
148+
149+ public UserCredential UpdateUserCredentials ( CloudIdentity identity , string userId , string username , string apiKey )
150+ {
131151 var urlPath = string . Format ( "v2.0/users/{0}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials" , userId ) ;
132- var request = new UpdateUserCredencialRequest { UserCredential = new UserCredential { Username = user . Username , APIKey = apiKey } } ;
152+ var request = new UpdateUserCredencialRequest { UserCredential = new UserCredential { Username = username , APIKey = apiKey } } ;
133153 var response = ExecuteRESTRequest < UserCredentialResponse > ( identity , urlPath , HttpMethod . POST , request ) ;
134154
135155 if ( response == null || response . Data == null )
@@ -280,24 +300,27 @@ public IdentityToken GetTokenInfo(CloudIdentity identity, bool forceCacheRefresh
280300
281301 public UserAccess Authenticate ( CloudIdentity identity )
282302 {
283- var auth = AuthRequest . FromCloudIdentity ( identity ) ;
284- var response = ExecuteRESTRequest < AuthenticationResponse > ( identity , "/v2.0/tokens" , HttpMethod . POST , auth , isTokenRequest : true ) ;
285-
286-
287- if ( response == null || response . Data == null || response . Data . UserAccess == null || response . Data . UserAccess . Token == null )
288- return null ;
289-
290- return response . Data . UserAccess ;
303+ return GetUserAccess ( identity , true ) ;
291304 }
292305
293- private UserAccess GetUserAccess ( CloudIdentity identity , bool forceCacheRefresh = false )
306+ public UserAccess GetUserAccess ( CloudIdentity identity , bool forceCacheRefresh = false )
294307 {
295308 var rackspaceCloudIdentity = identity as RackspaceCloudIdentity ;
296309
297310 if ( rackspaceCloudIdentity == null )
298311 throw new InvalidCloudIdentityException ( string . Format ( "Invalid Identity object. Rackspace Identity service requires an instance of type: {0}" , typeof ( RackspaceCloudIdentity ) ) ) ;
299312
300- var userAccess = _userAccessCache . Get ( string . Format ( "{0}/{1}" , rackspaceCloudIdentity . CloudInstance , rackspaceCloudIdentity . Username ) , ( ) => Authenticate ( rackspaceCloudIdentity ) , forceCacheRefresh ) ;
313+ var userAccess = _userAccessCache . Get ( string . Format ( "{0}/{1}" , rackspaceCloudIdentity . CloudInstance , rackspaceCloudIdentity . Username ) , ( ) =>
314+ {
315+ var auth = AuthRequest . FromCloudIdentity ( identity ) ;
316+ var response = ExecuteRESTRequest < AuthenticationResponse > ( identity , "/v2.0/tokens" , HttpMethod . POST , auth , isTokenRequest : true ) ;
317+
318+
319+ if ( response == null || response . Data == null || response . Data . UserAccess == null || response . Data . UserAccess . Token == null )
320+ return null ;
321+
322+ return response . Data . UserAccess ;
323+ } , forceCacheRefresh ) ;
301324
302325 return userAccess ;
303326 }
0 commit comments