File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
packages/core/src/lib/actions/callback/oauth Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -190,13 +190,23 @@ export async function handleOAuth(
190190 case "microsoft-entra-id" :
191191 case "azure-ad" : {
192192 /**
193- * These providers need the authorization server metadata to be re-processed
194- * based on the `id_token`'s `tid` claim
195- * @see https://github.com/MicrosoftDocs/azure-docs/issues/113944
193+ * These providers return errors in the response body and
194+ * need the authorization server metadata to be re-processed
195+ * based on the `id_token`'s `tid` claim.
196+ * @see : https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#error-response-1
196197 */
197- const { tid } = decodeJwt (
198- ( await codeGrantResponse . clone ( ) . json ( ) ) . id_token
199- )
198+ const responseJson = await codeGrantResponse . clone ( ) . json ( )
199+ if ( responseJson . error ) {
200+ const cause = {
201+ providerId : provider . id ,
202+ ...responseJson ,
203+ }
204+ throw new OAuthCallbackError (
205+ `OAuth Provider returned an error: ${ responseJson . error } ` ,
206+ cause
207+ )
208+ }
209+ const { tid } = decodeJwt ( responseJson . id_token )
200210 if ( typeof tid === "string" ) {
201211 const tenantRe = / m i c r o s o f t o n l i n e \. c o m \/ ( \w + ) \/ v 2 \. 0 /
202212 const tenantId = as . issuer ?. match ( tenantRe ) ?. [ 1 ] ?? "common"
You can’t perform that action at this time.
0 commit comments