How do you get an authorization token with pkce flow Azure AD B2C
Unanswered
Leafcutting bee posted this in #help-forum
Leafcutting beeOP
Hello,
I am having trouble finding documentation on how to get an authorization token using PKCE check with Azure AD B2C.
My login is successful, and I get an id token, but my understanding is that a new request must be made for the access token using the code in the pkce flow. The access token is not in the id token.
Is there a built in way to obtain the access token?
I am having trouble finding documentation on how to get an authorization token using PKCE check with Azure AD B2C.
My login is successful, and I get an id token, but my understanding is that a new request must be made for the access token using the code in the pkce flow. The access token is not in the id token.
Is there a built in way to obtain the access token?
import NextAuth, { NextAuthOptions } from "next-auth"
import AzureADB2CProvider from "next-auth/providers/azure-ad-b2c";
export const authOptions: NextAuthOptions = {
providers: [
AzureADB2CProvider({
tenantId: process.env.AZURE_AD_B2C_TENANT_NAME,
clientId: process.env.AZURE_AD_B2C_CLIENT_ID ?? "",
clientSecret: process.env.AZURE_AD_B2C_CLIENT_SECRET ?? "",
primaryUserFlow: process.env.AZURE_AD_B2C_PRIMARY_USER_FLOW,
authorization: { params: { scope: `openid https://${process.env.AZURE_AD_B2C_TENANT_NAME}.onmicrosoft.com/${process.env.EVENTOGRAPHY_API_CLIENT_ID}/Profile.Read` } },
// client: {
// token_endpoint_auth_method: 'none',
// },
checks: 'pkce',
}),
],
callbacks: {
async jwt({ token, user, account, profile }) {
return token;
},
async session({ session, token, user }) {
// token.accessToken does not exist after disabling implicit flow in Azure AD B2C
session.user.accessToken = token.accessToken;
session.user.id = token.sub;
return session;
}
},
session: {
strategy: 'jwt'
}
}
export default NextAuth(authOptions);