PowerShell
I found a little more code on how to generate tokens in PowerShell.
To use the PostMan scripts, you need a new client on the indentity server called postman-api
. Add this to the file \wwwroot\xxx.identityserver\Config\production\Sitecore.IdentityServer.Host.xml. This will allow us to call out custom client for openid.
<Clients>
<DefaultClient>
<AllowedCorsOrigins>
<AllowedCorsOriginsGroup1>https://habitathome.dev.local|https://habitathomebasic.dev.local</AllowedCorsOriginsGroup1>
</AllowedCorsOrigins>
</DefaultClient>
<PasswordClient>
<ClientSecrets>
<ClientSecret1>ClientSecret</ClientSecret1>
</ClientSecrets>
</PasswordClient>
<PostmanClient>
<ClientId>postman-api</ClientId>
<ClientName>postman-api</ClientName>
<AccessTokenType>0</AccessTokenType>
<AllowOfflineAccess>true</AllowOfflineAccess>
<AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
<AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
<IdentityTokenLifetimeInSeconds>3600</IdentityTokenLifetimeInSeconds>
<AllowAccessTokensViaBrowser>true</AllowAccessTokensViaBrowser>
<RequireConsent>false</RequireConsent>
<RequireClientSecret>true</RequireClientSecret>
<AllowedGrantTypes>
<AllowedGrantType1>password</AllowedGrantType1>
</AllowedGrantTypes>
<AllowedCorsOrigins>
</AllowedCorsOrigins>
<AllowedScopes>
<AllowedScope1>openid</AllowedScope1>
<AllowedScope2>sitecore.profile</AllowedScope2>
<AllowedScope3>sitecore.profile.api</AllowedScope3>
</AllowedScopes>
<ClientSecrets>
<ClientSecret1>ClientSecret</ClientSecret1>
</ClientSecrets>
<UpdateAccessTokenClaimsOnRefresh>true</UpdateAccessTokenClaimsOnRefresh>
</PostmanClient>
</Clients>
Finally you can use this PowerShell to generate a token. https://gist.github.com/johnkors/454c829aa63e7663745da5ebeb38dd86
The only issue I still have is that Sitecore will not validate the JWT token. My error is:
8604 01:14:45 ERROR Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware - Authentication failed
Exception: Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException Message: IDX10500: Signature validation failed. No security keys were provided to validate the signature.
Source: System.IdentityModel.Tokens.Jwt at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) in C:\agent2_work\15\s\src\System.IdentityModel.Tokens.Jwt\JwtSecurityTokenHandler.cs:line 1057 at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken) in C:\agent2_work\15\s\src\System.IdentityModel.Tokens.Jwt\JwtSecurityTokenHandler.cs:line 768 at Microsoft.Owin.Security.Jwt.JwtFormat.Unprotect(String protectedText) at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.d__0.MoveNext()