Skip to content

Commit b627d10

Browse files
author
Alan Quillin
committed
Add support for validating a token
1 parent 02b10b4 commit b627d10

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/corelib/Providers/Rackspace/CloudIdentityProvider.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,28 @@ public UserAccess Impersonate(RackspaceImpersonationIdentity identity, bool forc
737737
return impToken;
738738
}
739739

740+
/// <inheritdoc/>
741+
public UserAccess ValidateToken(string token, string tenantId = null, CloudIdentity identity = null)
742+
{
743+
if (token == null)
744+
throw new ArgumentNullException("token");
745+
if (string.IsNullOrEmpty(token))
746+
throw new ArgumentException("token cannot be empty");
747+
748+
var queryStringParameters = BuildOptionalParameterList(new Dictionary<string, string>
749+
{
750+
{"belongsTo", tenantId}
751+
});
752+
753+
var response = ExecuteRESTRequest<AuthenticationResponse>(identity, new Uri(_urlBase, string.Format("/v2.0/tokens/{0}", token)), HttpMethod.GET, queryStringParameter: queryStringParameters);
754+
755+
756+
if (response == null || response.Data == null || response.Data.UserAccess == null || response.Data.UserAccess.Token == null)
757+
return null;
758+
759+
return response.Data.UserAccess;
760+
}
761+
740762
private JObject BuildImpersonationRequestJson(string path, string userName, int expirationInSeconds)
741763
{
742764
var request = new JObject();

src/corelib/Providers/Rackspace/IExtendedCloudIdentityProvider.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,19 @@ public interface IExtendedCloudIdentityProvider : IIdentityProvider
349349
/// <exception cref="ResponseException">If the REST API request failed.</exception>
350350
/// <seealso href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_updateUserCredential_v2.0_users__userId__OS-KSADM_credentials__credential-type__.html">Update User Credentials (OpenStack Identity Service API v2.0 Reference)</seealso>
351351
UserCredential UpdateUserCredentials(string userId, string username, string apiKey, CloudIdentity identity = null);
352+
353+
/// <summary>
354+
/// Validates a given token.
355+
/// </summary>
356+
/// <param name="token">The token to be authenticated.</param>
357+
/// <param name="tenantId">The Id of the Tenant to vaidate in scope.</param>
358+
/// <param name="identity">The cloud identity to use for this request. If not specified, the default identity for the current provider instance will be used.</param>
359+
/// <returns>A <see cref="UserAccess"/> object containing the authentication token and user data.</returns>
360+
/// <exception cref="ArgumentNullException">If <paramref name="token"/> is <c>null</c>.</exception>
361+
/// <exception cref="ArgumentException">If <paramref name="token"/> is empty.</exception>
362+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
363+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.</exception>
364+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
365+
UserAccess ValidateToken(string token, string tenantId = null, CloudIdentity identity = null);
352366
}
353367
}

0 commit comments

Comments
 (0)