How do you solve Auth0's URL Mismatch error

1.9k views Asked by At

I'm trying to implement Auth0 with lock (version 10.11.0) inside my Angular2 app. Auth0 works if I list every possible route in Auth0's client's Allowed Callback URLs setting. It seems Auth0 picks up the callback URL from whatever URL the user happens to be on when they decide to login. This is not a scalable approach. How do you solve this?

I've tried entering a redirectUrl value in auth options. This gets me a little further in that the app does redirect to the URL supplied, however, Auth0 lock's authenticated callback never fires so I cannot retrieve authenticated user's profile.

So, I'm stuck. It seems my only course of action is to list every conceivable route in Auth0's client's Allowed Callback URLs setting and pray the guys from marketing do not come up with more routes.

Here's my code:

        let options =
        {
            auth:
            {
                //redirectUrl: 'http://localhost:4200',
                //redirect: true,
                responseType: 'token',
                params:
                {
                    scope: 'openid user_id name nickname email picture'
                }
            }
        };

        this.lock = new Auth0Lock('xxx', 'yyy', options);

        this.lock.on("authenticated", (authResult) =>
        {
            console.log('@@@@  AUTH RESULTS:', authResult); 

            localStorage.setItem('id_token', authResult.idToken);

            this.lock.getProfile(authResult.idToken, (error, profile) => 
            {
                if (error) 
                {
                    return;
                }

                console.log('@@@@  AUTHENTICATED USER PROFILE:', profile);

            });
        }

Any ideas on how to make Auth0 work so you do not have to list every possible route a user can be on before deciding to authenticate?

0

There are 0 answers