On login, I get userinfo Failed to load resource: the server responded with a status of 401 ().
var oktaConfig = {
issuer: “https://trial-8358756.okta.com/oauth2/default ”,
redirectUri: ‘https://localhost:44367/home ’,
clientId: “0oa3lfeevz0nT1C93697”,
scope:“openid email profile”
The get for userinfo fails with a 402 error
GET https://trial-8358756.okta.com/oauth2/default/v1/userinfo 401
Also, the idToken.claims.scopes only indicates openid and email
erik
December 15, 2022, 12:37am
2
Hello,
Are you passing the accees_token in the Authorization header?
curl -X GET \
-H "Authorization: Bearer ${access_token}" \
"https://${baseUrl}/userinfo"
Thank You,
1 Like
I’m using the widget, so this is the code:
const oktaSignIn = new OktaSignIn(oktaConfig);
oktaSignIn.authClient.token.getUserInfo().then(function (user) {
document.getElementById(“messageBox”).innerHTML = "Hello, " + user.email + “! You are still logged in! :)”;
document.getElementById(“logout”).style.display = ‘block’;
console.log(“Still logged in”);
console.log("Name : " + user.email + ", " + user.name + ", " + user.firstName);
console.log("displayName : " + user.displayname + “name:” + user.family_name + user.lastname + user.email);
}, function (error) {
oktaSignIn.showSignInToGetTokens({
el: ‘#okta-login-container ’
}).then(function (tokens) {
oktaSignIn.authClient.tokenManager.setTokens(tokens);
oktaSignIn.remove();
//alert(“Okta login”);
const idToken = tokens.idToken;
document.getElementById(“messageBox”).innerHTML = "Hello, " + idToken.claims.email + “! You just logged in! :)”;
document.getElementById(“logout”).style.display = ‘block’;
console.log("You logged in " + idToken.claims.family_name + ", " + idToken.claims.username + ", " + idToken.claims.email);
console.log("displayName : " + idToken.claims.displayName);
erik
December 15, 2022, 9:56pm
4
Hello,
Your config passed to OktaSignIn()
needs to embed the authorize params,
var oktaConfig = {
redirectUri: ‘https://localhost:44367/home’,
clientId: “0oa3lfeevz0nT1C93697”,
authParams: {
“https://trial-8358756.okta.com/oauth2/default”,
scopes: ['openid', 'profile', 'email']
}
}
oktaSignIn.authClient.token.getUserInfo()
uses the error function to login a user.
I would expect you will see this error each time you load the page when there is not an existing valid token storage.
Thank You,