Skip to content

Instantly share code, notes, and snippets.

@fcgdam
Created November 8, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcgdam/dd44fd32c6d98e9a66c75480f330bc49 to your computer and use it in GitHub Desktop.
Save fcgdam/dd44fd32c6d98e9a66c75480f330bc49 to your computer and use it in GitHub Desktop.
Simple Client Credentials test with node-openid-client
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