I am getting this error on Azure AD B2C login
AADB2C90006: The redirect URI 'http://localhost:3001/' provided in the request is not registered for the client id '714f2acb-2483-4759-9114-f6c2df737b5d'.
I have added web redirect url like this:
following is the react side code
import { LogLevel } from "@azure/msal-browser";
export const b2cPolicies = {
names: {
signUpSignIn: 'B2C_1_signupsignin1',
forgotPassword: 'B2C_1_reset_v3',
editProfile: 'B2C_1_editprofile',
},
authorities: {
signUpSignIn: {
authority: 'https://testingtenant311.b2clogin.com/testingtenant311.onmicrosoft.com/B2C_1_signupsignin1',
},
forgotPassword: {
authority: 'https://testingtenant311.b2clogin.com/testingtenant311.onmicrosoft.com/B2C_1_reset_v3',
},
editProfile: {
authority: 'https://testingtenant311.b2clogin.com/testingtenant311.onmicrosoft.com/B2C_1_editprofile',
},
},
authorityDomain: 'testingtenant311.b2clogin.com',
};
export const msalConfig = {
auth: {
clientId: '714f2acb-2483-4759-9114-f6c2df737b5d',
authority: b2cPolicies.authorities.signUpSignIn.authority,
knownAuthorities: [b2cPolicies.authorityDomain],
redirectUri: '/',
postLogoutRedirectUri: '/',
navigateToLoginRequestUrl: false,
},
cache: {
cacheLocation: 'sessionStorage',
storeAuthStateInCookie: false,
},
system: {
loggerOptions: {
loggerCallback: (level: any, message: any, containsPii: any) => {
if (containsPii) {
return;
}
switch (level) {
case LogLevel.Error:
console.error(message);
return;
case LogLevel.Info:
// console.info(message);
return;
case LogLevel.Verbose:
console.debug(message);
return;
case LogLevel.Warning:
console.warn(message);
return;
default:
return;
}
},
},
},
};
export const protectedResources = {
apiTodoList: {
endpoint: 'http://localhost:5000/api/todolist',
scopes: {
read: ['https://fabrikamb2c.onmicrosoft.com/TodoList/ToDoList.Read'],
write: ['https://fabrikamb2c.onmicrosoft.com/TodoList/ToDoList.ReadWrite'],
},
},
};
export const loginRequest = {
scopes: [...protectedResources.apiTodoList.scopes.read],
};
Please help me solve this error.
Thanks in advance
The error "The redirect URI 'http://localhost:3001/' provided in the request is not registered for the client id 'XXX'" usually occurs if the redirect URL is not configured in the Azure AD B2C application.
Cross verify whether you have configured the redirect URL in the correct application:
If still the issue persists, pass the redirect URL in the code too in the redirectUri
parameter:
export const msalConfig = {
auth: {
clientId: 'ClientID',
authority: b2cPolicies.authorities.signUpSignIn.authority,
knownAuthorities: [b2cPolicies.authorityDomain],
redirectUri: 'http://localhost:3001',
postLogoutRedirectUri: '/',
navigateToLoginRequestUrl: false,
},
Note that: After saving the changes or adding the new redirect URL it might take three to five minutes for the changes to take effect. Refer this MsDoc