I'm doing LinkedIn authentication with auth0 in a react app. I have set localhost:3000/upload
in callback urls in settings, hopping that after users login at localhost:3000/login
, they would be redirect to localhost:3000/upload
. However, I always get this error: url localhost:3000/login
is not in the list of callback urls. Why would auth0 expect to return to the page where you just logged in at after logging in. isnt it supposed to be some different urls. it just doesnt make sense to me.
Edit:
export default class AuthService {
constructor(clientId, domain) {
// Configure Auth0
const options = {
allowedConnections: ['linkedin'],
auth: {
params: {responseType: 'code'}
}
};
this.lock = new Auth0Lock(clientId, domain, options)
// Add callback for lock `authenticated` event
this.lock.on('authenticated', this._doAuthentication.bind(this))
// binds login functions to keep this context
this.login = this.login.bind(this)
this.loggedIn = this.loggedIn.bind(this)
}
_doAuthentication(authResult){
// Saves the user token
console.log(authResult);
this.setToken(authResult.idToken)
this.lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
console.log('Error loading the Profile', error)
} else {
console.log(profile)
}
})
}
//....
To cause a redirect to a different URL after a successful authentication, you need to provide the redirectUrl
to Lock, like this:
// Configure Auth0
const options = {
allowedConnections: ['linkedin'],
auth: {
responseType: 'code',
redirectUrl: 'http://localhost:3000/upload'
}
};
this.lock = new Auth0Lock(clientId, domain, options)
(Also notice that the responseType
option goes under auth
, not under auth.params
.)
If you do the redirect, you won't reach the event handler you defined in your login page. You will need to either add an event handler in your destination page (and use responseType:token
) or handle authentication results in your server code (this is what you will normally be doing if you are requesting a responseType: code
).
Make sure that there is no special hidden characters or space between the commas between the URLs when you paste it into the Auth0 Setting site. I didn't realise about this util I put every urls into Vim to check and see that there are such above cases
来源:https://stackoverflow.com/questions/38556763/auth0-callback-url-mismatch