Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Authentication failed due to: In Strategy.prototype.jwtVerify: cannot verify token #8

Closed
Kilio22 opened this issue Jun 24, 2020 · 2 comments

Comments

@Kilio22
Copy link

Kilio22 commented Jun 24, 2020

Hi there,

After following theses tutorials: https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-expose-web-apis & https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis, I'm getting this error message when trying to GET /hello using react:
authentication failed due to: In Strategy.prototype.jwtVerify: cannot verify token

Here's the full trace:

{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"In Strategy.prototype.authenticate: received metadata","time":"2020-06-24T16:30:49.636Z","v":0}
{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"In Strategy.prototype.authenticate: we will validate the options","time":"2020-06-24T16:30:49.655Z","v":0}
{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"In Strategy.prototype.authenticate: access_token is received from request header","time":"2020-06-24T16:30:49.655Z","v":0}
{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"In Strategy.prototype.jwtVerify: token is decoded","time":"2020-06-24T16:30:49.656Z","v":0}
{"name":"AzureAD: Metadata Parser","hostname":"Kylian","pid":18560,"level":30,"msg":"working on key","time":"2020-06-24T16:30:49.656Z","v":0}
{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"PEMkey generated","time":"2020-06-24T16:30:49.657Z","v":0}
{"name":"AzureAD: Bearer Strategy","hostname":"Kylian","pid":18560,"level":30,"msg":"authentication failed due to: In Strategy.prototype.jwtVerify: cannot verify token","time":"2020-06-24T16:30:49.675Z","v":0}

Here's my code from react side:

try {
            const accessToken = await this.userAgentApplication.acquireTokenSilent({
                scopes: scopes
            });

            if (accessToken) {
                console.log(accessToken);
                ....
                fetch("http://localhost:5000/hello", {
                    method: 'GET',
                    headers: {
                        "Authorization": `Bearer ${accessToken.accessToken}`,
                        "Content-Type": 'application/json'
                    }
                })
            }
        } catch (err) {
            ...
        }
    }

Here's the config.js file:

const config = {
    identityMetadata: "https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration",
    clientID: <client-id>,
    validateIssuer: false,
    loggingLevel: 'info',
    passReqToCallback: false
};

module.exports = config

Am I doing something wrong ?
I did a lot of search on google and I still can't find where is the problem :/

Regards,

Kilio22

@Kilio22
Copy link
Author

Kilio22 commented Jun 25, 2020

I've fixed it, there was a problem with scopes, sry for notification

@Kilio22 Kilio22 closed this as completed Jun 25, 2020
@tauseefanwr
Copy link

It would be great if you can post where did you make the changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants