Commit d873090f authored by alan.f's avatar alan.f

add access-token-and-id-token

parent 4402f5c6
......@@ -13,7 +13,7 @@ namespace ApiOne.Controllers
[Authorize]
public string Index()
{
//var claims = User.Claims.ToList();
var claims = User.Claims.ToList();
return "secret message from ApiOne";
}
}
......
......@@ -27,7 +27,7 @@ namespace IdentityServer
new List<ApiResource>
{
new ApiResource("ApiOne"),
new ApiResource("ApiTwo"),
new ApiResource("ApiTwo",new string[]{"rc.api.grandma"}),
};
public static IEnumerable<Client> GetClients() =>
new List<Client>
......
......@@ -25,6 +25,8 @@ namespace IdentityServer
userManager.CreateAsync(user, "password").GetAwaiter().GetResult();
userManager.AddClaimAsync(user, new Claim("rc.garndma", "big.cookie"))
.GetAwaiter().GetResult();
userManager.AddClaimAsync(user, new Claim("rc.api.garndma", "big..api.cookie"))
.GetAwaiter().GetResult();
}
host.Run();
}
......
......@@ -38,18 +38,18 @@ namespace MvcClient.Controllers
var result = await GetSecret(accessToken);
await RefreshAccessToken();
//await RefreshAccessToken();
return View();
}
public async Task<string> GetSecret(string accessToken)
public async Task<string> GetSecret(string accessToken)
{
var apiClient = _httpClientFactory.CreateClient();
apiClient.SetBearerToken(accessToken);
var response = await apiClient.GetAsync("https://localhost:44337/secret");
var response = await apiClient.GetAsync("https://localhost:44340/secret");
var content = await response.Content.ReadAsStringAsync();
......@@ -59,8 +59,8 @@ namespace MvcClient.Controllers
private async Task RefreshAccessToken()
{
var serverClient = _httpClientFactory.CreateClient();
var discoveryDocument = await serverClient.GetDiscoveryDocumentAsync("https://localhost:44305/");
var discoveryDocument = await serverClient.GetDiscoveryDocumentAsync("https://localhost:44325/");
var accessToken = await HttpContext.GetTokenAsync("access_token");
var idToken = await HttpContext.GetTokenAsync("id_token");
var refreshToken = await HttpContext.GetTokenAsync("refresh_token");
......
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
......@@ -27,12 +28,19 @@ namespace MvcClient
config.ResponseType = "code";
//config cookie claim mapping
config.ClaimActions.DeleteClaim("amr");
config.ClaimActions.MapUniqueJsonKey("ReadaCoding.Grandma","rc.grandma");
//two trips to load claims in to the cookie
config.GetClaimsFromUserInfoEndpoint = true;
//configure scope
config.Scope.Clear();
config.Scope.Add("openid");
config.Scope.Add("rc.scope");
config.Scope.Add("ApiOne");
config.Scope.Add("ApiTwo");
} );
services.AddHttpClient();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment