Created
November 8, 2019 11:12
-
-
Save fcgdam/dd44fd32c6d98e9a66c75480f330bc49 to your computer and use it in GitHub Desktop.
Simple Client Credentials test with node-openid-client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const OpenIdClient = require("openid-client"); | |
const identityUrl = "http://127.0.0.1:3000/"; | |
const clientId = "user1"; | |
const clientSecret = "password"; | |
async function GetAccessToken() { | |
var issuer = await OpenIdClient.Issuer.discover(identityUrl); | |
const client = new issuer.Client({ | |
client_id: clientId, | |
client_secret: clientSecret, | |
response_types: ['id_token'], | |
grant_types: [ "implicit", "authorization_code" ], | |
application_type: "native" | |
}); | |
var grantResponse = await client.grant({ | |
grant_type: 'client_credentials', | |
scope: 'openid profile' | |
}); | |
var accessToken = grantResponse.access_token | |
console.log(" The GrantResponse: " , grantResponse ); | |
console.log(" The Access token: " , accessToken ); | |
// Introspect the token now: | |
const response = await client.introspect( accessToken ); | |
console.log( "----------- Token Introspection: "); | |
console.log( response ); | |
console.log( "------------ User info: "); | |
const userinfo = await client.userinfo( grantResponse ); // Or accessToken <---- IT FAILS HERE with TOKEN NOT FOUND returned from the server | |
console.log( userinfo ); | |
} | |
GetAccessToken(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment