Skip to content

Commit 82c22d4

Browse files
committed
Merge pull request #197 from sharwell/validate-token
ValidateToken updates
2 parents 051f9b1 + cdd7e7a commit 82c22d4

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

src/corelib/Core/Providers/IIdentityProvider.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ public interface IIdentityProvider
2626
/// <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>
2727
UserAccess Authenticate(CloudIdentity identity = null);
2828

29+
/// <summary>
30+
/// Validates a given token.
31+
/// </summary>
32+
/// <param name="token">The token to be validated.</param>
33+
/// <param name="tenantId">If specified, the validation ensures that the specified tenant is in scope. This is obtained from <see cref="Tenant.Id"/>.</param>
34+
/// <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>
35+
/// <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>
36+
/// <exception cref="ArgumentNullException">If <paramref name="token"/> is <c>null</c>.</exception>
37+
/// <exception cref="ArgumentException">If <paramref name="token"/> is empty.</exception>
38+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
39+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <c>null</c> and no default identity is available for the provider.</exception>
40+
/// <exception cref="ItemNotFoundException">If <paramref name="tenantId"/> is specified and the token is not valid within the specified tenant.</exception>
41+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
42+
/// <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>
43+
UserAccess ValidateToken(string token, string tenantId = null, CloudIdentity identity = null);
44+
2945
/// <summary>
3046
/// Gets the authentication token for the specified identity. If necessary, the identity is authenticated
3147
/// on the server to obtain a token.

src/corelib/Providers/Rackspace/IExtendedCloudIdentityProvider.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,5 @@ 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);
366352
}
367353
}

src/testing/integration/Providers/Rackspace/UserIdentityTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ public void TestAuthenticate()
6868
Console.WriteLine(JsonConvert.SerializeObject(userAccess, Formatting.Indented));
6969
}
7070

71+
/// <summary>
72+
/// This method tests the basic functionality of the <see cref="IIdentityProvider.ValidateToken"/>
73+
/// method for a validated token.
74+
/// </summary>
75+
[TestMethod]
76+
[TestCategory(TestCategories.User)]
77+
[TestCategory(TestCategories.Identity)]
78+
public void TestValidateToken()
79+
{
80+
IIdentityProvider provider = new CloudIdentityProvider(Bootstrapper.Settings.TestIdentity);
81+
UserAccess userAccess = provider.Authenticate();
82+
83+
Assert.IsNotNull(userAccess);
84+
Assert.IsNotNull(userAccess.Token);
85+
Assert.IsNotNull(userAccess.Token.Id);
86+
87+
UserAccess validated = provider.ValidateToken(userAccess.Token.Id);
88+
Assert.IsNotNull(validated);
89+
Assert.IsNotNull(validated.Token);
90+
Assert.AreEqual(userAccess.Token.Id, validated.Token.Id);
91+
92+
Assert.IsNotNull(validated.User);
93+
Assert.AreEqual(userAccess.User.Id, validated.User.Id);
94+
Assert.AreEqual(userAccess.User.Name, validated.User.Name);
95+
Assert.AreEqual(userAccess.User.DefaultRegion, validated.User.DefaultRegion);
96+
}
97+
7198
[TestMethod]
7299
[TestCategory(TestCategories.User)]
73100
[TestCategory(TestCategories.Identity)]

0 commit comments

Comments
 (0)