How can I get values in id_token in Fetch User Profile Script

I’m looking for ways to get values in id_token in fetch user profile script of custom social connector. Some identity providers which support OIDC hybrid flow return id_token with access token and I want to fetch some of user attributes from id_token.
I tried to access id_token in the script like “ctx.idToken”, but it did not work.

Does anyone have solution for this?

Hi Naohiro, have you ever found a solution for this? I am facing the same problem.

Hi,

I could access id_token through ctx object, but I have not found a way to get value in jwt yet.

var i = ctx.id_token;
→ I could get base64url encoded id_token.

Do you know how to decode this in the script?

1 Like

Hello,

Now I found a way to get claims from id_token. Try this.

function(accessToken, ctx, cb) {
  var i = jwt.decode(ctx.id_token);
  var p = {
    name: i.sub
  };
  cb(null,p);
}
1 Like

Thank you so much for your reply!
I can now access the id_token, however when I try to use jwt to decode it I get an error “jwt.decode is not a function”, did you get the same error?

No, I didn’t get the same error.

Which version of Custom Social Connections Extension do you use? I’m using version 1.2.

I use 1.2 as well.
I was able to resolve the issue though by adding a require statement in the body of the function
var jwt = require('jsonwebtoken');

1 Like

Hey @Naohiro!

Let us know if what @yellow.bridge suggested work for you otherwise I’ll try to dig into it further!

Hi @konrad.sopala

I believe now my code works fine for @yellow.bridge .

Do I have to close this issue?

Great to hear that! No worries I just mark his response as a solution. You don’t need to take any actions :slight_smile:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.