From cf0612fb9e483177c5d1c665fb9eccc64560a041 Mon Sep 17 00:00:00 2001 From: Ernesto Ramos Rio Date: Sun, 29 Nov 2020 08:04:54 -0500 Subject: [PATCH] adding endpoint to get token from identity provider --- .../IdentityProviders/KeycloakClient.cs | 11 ++++++++ .../IdentityProviderToken.cs | 25 +++++++++++++++++++ .../IdentityProviders/KeycloakClientShould.cs | 8 ++++++ 3 files changed, 44 insertions(+) create mode 100644 src/Keycloak.Net/Models/IdentityProviders/IdentityProviderToken.cs diff --git a/src/Keycloak.Net/IdentityProviders/KeycloakClient.cs b/src/Keycloak.Net/IdentityProviders/KeycloakClient.cs index b2e58605..96d83b83 100644 --- a/src/Keycloak.Net/IdentityProviders/KeycloakClient.cs +++ b/src/Keycloak.Net/IdentityProviders/KeycloakClient.cs @@ -34,6 +34,17 @@ public async Task GetIdentityProviderAsync(string realm, strin .GetJsonAsync() .ConfigureAwait(false); + /// + /// + /// + /// + /// + /// + public async Task GetIdentityProviderTokenAsync(string realm, string identityProviderAlias) => await GetBaseUrl(realm) + .AppendPathSegment($"/auth/realms/{realm}/broker/{identityProviderAlias}/token") + .GetJsonAsync() + .ConfigureAwait(false); + public async Task UpdateIdentityProviderAsync(string realm, string identityProviderAlias, IdentityProvider identityProvider) { var response = await GetBaseUrl(realm) diff --git a/src/Keycloak.Net/Models/IdentityProviders/IdentityProviderToken.cs b/src/Keycloak.Net/Models/IdentityProviders/IdentityProviderToken.cs new file mode 100644 index 00000000..bd3fc8cd --- /dev/null +++ b/src/Keycloak.Net/Models/IdentityProviders/IdentityProviderToken.cs @@ -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; } + } +} \ No newline at end of file diff --git a/test/Keycloak.Net.Tests/IdentityProviders/KeycloakClientShould.cs b/test/Keycloak.Net.Tests/IdentityProviders/KeycloakClientShould.cs index af0491f7..adb8b695 100644 --- a/test/Keycloak.Net.Tests/IdentityProviders/KeycloakClientShould.cs +++ b/test/Keycloak.Net.Tests/IdentityProviders/KeycloakClientShould.cs @@ -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)