The Code_Verifier does not match the code_challenge
See original GitHub issueLibrary
-
msal@1.x.x
or@azure/msal@1.x.x
-
@azure/msal-browser@2.x.x
-
@azure/msal-node@1.x.x
-
@azure/msal-react@1.x.x
-
@azure/msal-angular@0.x.x
-
@azure/msal-angular@1.x.x
-
@azure/msal-angular@2.x.x
-
@azure/msal-angularjs@1.x.x
Framework
- Angular
- React
- Other
Description
Error Message
Uncaught (in promise) ServerError: invalid_grant: 501481 - [2021-03-19 13:18:03Z]: AADSTS501481: The Code_Verifier does not match the code_challenge supplied in the authorization request.
MSAL Configuration
const initMsal = ({msalConfig}) => {
const postLogoutRedirectUri =
process.env.AZURE_AD_REDIRECT_URL + '?redirectTo=' + origin + '/logout'
const auth = {
postLogoutRedirectUri,
cloudDiscoveryMetadata,
authorityMetadata,
...msalConfig.auth
}
const cache = {cacheLocation: 'localStorage', ...msalConfig.cache}
const config = {...msalConfig, auth, cache}
return new PublicClientApplication(config)
}
Reproduction steps
I’m using silent SSO and using a cross-domain postMessage broker to retrieve the login hint. The first time the page is loaded (clean cache) I get the above error. It would further seem that the user is actually logged in: .getAllAccounts()
has an account and the next load logs the user in instantly. Didn’t include code as it doesn’t seem pertinent, would be happy to provide anything necessary.
Expected behavior
The user should log in with no interaction
Identity Provider
- Azure AD
- Azure B2C Basic Policy
- Azure B2C Custom Policy
- ADFS
- Other
Browsers/Environment
- Chrome
- Firefox
- Edge
- Safari
- IE
- Other (Please add browser name here)
Regression
- Did this behavior work before? Version:
Security
- Is this issue security related?
Source
- Internal (Microsoft)
- Customer request
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
IdentityServer4 PKCE error: "Transformed code verifier does ...
but I cannot find the code in the repositories for the ToCodeChallenge method. Why doesn't my manually generated challenge match the one used...
Read more >The code_verifier sent does not match code_challenge ...
I'm using the code_verifier value same as the code_challenge used to obtain the auth code. Wondering why Ping Fed need Code Challenge and...
Read more >Value passed for the code verifier did not match the code ...
I want to get a access token and a refresh token in Postman. But I am confuse that the API always reports that:...
Read more >PKCE Code verifier is incorrect for Angular 12 production build
... experiencing: Running everything locally in dev build -> IdentityServer says: Transformed code verifier does not match code challenge
Read more >IdentityServer/IdentityServer4 - Gitter
hey @Arkatufus I'm getting a Transformed code verifier does not match code challenge error now when trying to request an access_token after authorization ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found that the application code is passing in
state
with the current url and making severalssoSilent
requests. On the 2nd call to the /authorize endpoint this url stored instate
somehow has the response hash from the first call to the /authorize endpoint this results in a response url that has 2 codes in it: thecode
returned from the server and thecode
from the first call that was added tostate
. This resulted in a mismatch when exchanging the code for a token.Mitigations are to:
state
redirectUri
is not invoking msal APIs or altering the hash on page load (you can use a blank page for silent and popup scenarios)MSAL should be blocking auth requests inside hidden iframes so it’s not clear how the 2nd call is getting the response url from the first.
@mbrevda This is likely a usage issue, can you provide as much relevant code so that I can try to reproduce? Also a fiddler trace would be helpful so I can check against server logs. You can email it to me, my emails on my profile. Thanks!