Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/corelib/Core/Providers/IIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ public interface IIdentityProvider
/// <seealso href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_.html">Authenticate (OpenStack Identity Service API v2.0 Reference)</seealso>
UserAccess Authenticate(CloudIdentity identity = null);

/// <summary>
/// Validates a given token.
/// </summary>
/// <param name="token">The token to be validated.</param>
/// <param name="tenantId">If specified, the validation ensures that the specified tenant is in scope. This is obtained from <see cref="Tenant.Id"/>.</param>
/// <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>
/// <returns>A <see cref="UserAccess"/> object containing the authentication token and user data. The <see cref="UserAccess.ServiceCatalog"/> property of the result may be <c>null</c>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="token"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <paramref name="token"/> is empty.</exception>
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.</exception>
/// <exception cref="ItemNotFoundException">If <paramref name="tenantId"/> is specified and the token is not valid within the specified tenant.</exception>
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
/// <seealso href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/GET_validateToken_v2.0_tokens__tokenId__Token_Operations.html">Validate Token (OpenStack Identity Service API v2.0 Reference)</seealso>
UserAccess ValidateToken(string token, string tenantId = null, CloudIdentity identity = null);

/// <summary>
/// Gets the authentication token for the specified identity. If necessary, the identity is authenticated
/// on the server to obtain a token.
Expand Down
14 changes: 0 additions & 14 deletions src/corelib/Providers/Rackspace/IExtendedCloudIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,5 @@ public interface IExtendedCloudIdentityProvider : IIdentityProvider
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <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>
UserCredential UpdateUserCredentials(string userId, string username, string apiKey, CloudIdentity identity = null);

/// <summary>
/// Validates a given token.
/// </summary>
/// <param name="token">The token to be authenticated.</param>
/// <param name="tenantId">The Id of the Tenant to vaidate in scope.</param>
/// <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>
/// <returns>A <see cref="UserAccess"/> object containing the authentication token and user data.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="token"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <paramref name="token"/> is empty.</exception>
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.</exception>
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
UserAccess ValidateToken(string token, string tenantId = null, CloudIdentity identity = null);
}
}
27 changes: 27 additions & 0 deletions src/testing/integration/Providers/Rackspace/UserIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ public void TestAuthenticate()
Console.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));
}

/// <summary>
/// This method tests the basic functionality of the <see cref="IIdentityProvider.ValidateToken"/>
/// method for a validated token.
/// </summary>
[TestMethod]
[TestCategory(TestCategories.User)]
[TestCategory(TestCategories.Identity)]
public void TestValidateToken()
{
IIdentityProvider provider = new CloudIdentityProvider(Bootstrapper.Settings.TestIdentity);
UserAccess userAccess = provider.Authenticate();

Assert.IsNotNull(userAccess);
Assert.IsNotNull(userAccess.Token);
Assert.IsNotNull(userAccess.Token.Id);

UserAccess validated = provider.ValidateToken(userAccess.Token.Id);
Assert.IsNotNull(validated);
Assert.IsNotNull(validated.Token);
Assert.AreEqual(userAccess.Token.Id, validated.Token.Id);

Assert.IsNotNull(validated.User);
Assert.AreEqual(userAccess.User.Id, validated.User.Id);
Assert.AreEqual(userAccess.User.Name, validated.User.Name);
Assert.AreEqual(userAccess.User.DefaultRegion, validated.User.DefaultRegion);
}

[TestMethod]
[TestCategory(TestCategories.User)]
[TestCategory(TestCategories.Identity)]
Expand Down