Skip to content

Commit

Permalink
new token accessor endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
rajanadar committed Aug 31, 2016
1 parent 4806c50 commit 9abf2d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/VaultSharp/IVaultClient.cs
Expand Up @@ -705,6 +705,17 @@ public interface IVaultClient
/// </returns>
Task<Secret<TokenInfo>> GetTokenInfoAsync(string token);

/// <summary>
/// Gets the properties of the token associated with the accessor,
/// except the token ID.
/// This is meant for purposes where there is no access to token ID
/// but there is need to fetch the properties of a token.
/// </summary>
/// <param name="tokenAccessor"><para>[required]</para>
/// Accessor of the token to lookup.</param>
/// <returns>The token info.</returns>
Task<Secret<TokenInfo>> GetTokenInfoByAccessorAsync(string tokenAccessor);

/// <summary>
/// Revokes a token and all child tokens if the <see cref="revokeAllChildTokens" /> value is <value>true</value>.
/// When the token is revoked, all secrets generated with it are also revoked.
Expand All @@ -719,6 +730,16 @@ public interface IVaultClient
/// </returns>
Task RevokeTokenAsync(string token, bool revokeAllChildTokens);

/// <summary>
/// Revokes the token associated with the accessor and all the child tokens.
/// This is meant for purposes where there is no access to token ID
/// but there is need to revoke a token and its children.
/// </summary>
/// <param name="tokenAccessor"><para>[required]</para>
/// Accessor of the token.</param>
/// <returns>The token info.</returns>
Task RevokeTokenByAccessorAsync(string tokenAccessor);

/// <summary>
/// Revokes the calling client token and all child tokens.
/// When the token is revoked, all secrets generated with it are also revoked.
Expand Down
19 changes: 18 additions & 1 deletion src/VaultSharp/VaultClient.cs
Expand Up @@ -640,7 +640,16 @@ public async Task<Secret<TokenInfo>> GetTokenInfoAsync(string token)
{
Checker.NotNull(token, "token");

return await MakeVaultApiRequest<Secret<TokenInfo>>("auth/token/lookup/" + token, HttpMethod.Get).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
var requestData = new {token = token};
return await MakeVaultApiRequest<Secret<TokenInfo>>("auth/token/lookup", HttpMethod.Post, requestData).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
}

public async Task<Secret<TokenInfo>> GetTokenInfoByAccessorAsync(string tokenAccessor)
{
Checker.NotNull(tokenAccessor, "tokenAccessor");

var requestData = new { accessor = tokenAccessor };
return await MakeVaultApiRequest<Secret<TokenInfo>>("auth/token/lookup-accessor", HttpMethod.Post, requestData).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
}

public async Task RevokeTokenAsync(string token, bool revokeAllChildTokens)
Expand All @@ -651,6 +660,14 @@ public async Task RevokeTokenAsync(string token, bool revokeAllChildTokens)
await MakeVaultApiRequest("auth/token/" + action + "/" + token, HttpMethod.Post).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
}

public async Task RevokeTokenByAccessorAsync(string tokenAccessor)
{
Checker.NotNull(tokenAccessor, "tokenAccessor");

var requestData = new { accessor = tokenAccessor };
await MakeVaultApiRequest("auth/token/revoke-accessor", HttpMethod.Post, requestData).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
}

public async Task RevokeCallingTokenAsync()
{
await MakeVaultApiRequest("auth/token/revoke-self", HttpMethod.Post).ConfigureAwait(continueOnCapturedContext: _continueAsyncTasksOnCapturedContext);
Expand Down
8 changes: 8 additions & 0 deletions test/VaultSharp.UnitTests/End2End/VaultClientEnd2EndTests.cs
Expand Up @@ -672,6 +672,14 @@ private async Task TokenTests()
var accessors = await _authenticatedClient.GetTokenAccessorListAsync();
Assert.True(accessors.Data.Any());

var tokenInfoByAccessor = await _authenticatedClient.GetTokenInfoByAccessorAsync(accessors.Data.First());
Assert.NotNull(tokenInfoByAccessor);

await _authenticatedClient.RevokeTokenByAccessorAsync(accessors.Data.First());

var accessors2 = await _authenticatedClient.GetTokenAccessorListAsync();
Assert.True(accessors.Data.Count() - 1 == accessors2.Data.Count());

var secret3 = await _authenticatedClient.CreateTokenAsync(new TokenCreationOptions { NoParent = true });
Assert.NotNull(secret3);

Expand Down

0 comments on commit 9abf2d1

Please sign in to comment.