I have an ASP.NET Core MVC application that allows anonymous users. This application calls the ASP.NET web API, which is protected by Identity Server 4. I created a client in Identity Server that describes the MVC application (client) and gave it access to the api area as follows:
new Client
{
ClientId = "my-mvc-client-app",
AllowedGrantTypes = GrantTypes.ClientCredentials,
RequireConsent = false,
ClientSecrets = new List<Secret> { new Secret("this-is-my-secret".Sha256()) },
AllowedScopes = new List<string>
{
StandardScopes.OpenId.Name,
StandardScopes.Profile.Name,
StandardScopes.OfflineAccess.Name,
"my-protected-api"
},
RedirectUris = new List<string>
{
"http://localhost:5009/signin-oidc",
}
}
In my MVC application, I use TokenClientto get a token that I can use when accessing the secure API as follows:
var disco = await DiscoveryClient.GetAsync("http://localhost:5010");
var tokenClient = new TokenClient(disco.TokenEndpoint, clientId, clientSecret);
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("hrmts-test-candidate-api-scope");
This works fine, but I am requesting new tokens from Identity Server for each request, which is probably not a good idea.
? ( MVC) , , , ?