Skip to content

Commit

Permalink
adding endpoint to get token from identity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
eramosr17 committed Nov 29, 2020
1 parent 4e2a542 commit cf0612f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Keycloak.Net/IdentityProviders/KeycloakClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public async Task<IdentityProvider> GetIdentityProviderAsync(string realm, strin
.GetJsonAsync<IdentityProvider>()
.ConfigureAwait(false);

/// <summary>
/// <see cref="https://github.com/keycloak/keycloak-documentation/blob/master/server_development/topics/identity-brokering/tokens.adoc"/>
/// </summary>
/// <param name="realm"></param>
/// <param name="identityProviderAlias"></param>
/// <returns></returns>
public async Task<IdentityProviderToken> GetIdentityProviderTokenAsync(string realm, string identityProviderAlias) => await GetBaseUrl(realm)
.AppendPathSegment($"/auth/realms/{realm}/broker/{identityProviderAlias}/token")
.GetJsonAsync<IdentityProviderToken>()
.ConfigureAwait(false);

public async Task<bool> UpdateIdentityProviderAsync(string realm, string identityProviderAlias, IdentityProvider identityProvider)
{
var response = await GetBaseUrl(realm)
Expand Down
25 changes: 25 additions & 0 deletions src/Keycloak.Net/Models/IdentityProviders/IdentityProviderToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace Keycloak.Net.Models.IdentityProviders
{
public class IdentityProviderToken
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }

[JsonProperty("token_type")]
public string RequestingPartyToken { get; set; }

[JsonProperty("expires_in")]
public int ExpiresIn { get; set; }

[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }

[JsonProperty("scope")]
public string Scope { get; set; }

[JsonProperty("created_at")]
public long CreatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public async Task GetIdentityProviderAsync(string realm)
}
}

//[Theory]
//[InlineData("Insurance")]
//public async Task GetIdentityProviderTokenAsync(string realm)
//{
// var token = await _client.GetIdentityProviderTokenAsync(realm).ConfigureAwait(false);
// Assert.NotNull(token);
//}

[Theory]
[InlineData("Insurance")]
public async Task GetIdentityProviderAuthorizationPermissionsInitializedAsync(string realm)
Expand Down

0 comments on commit cf0612f

Please sign in to comment.