4

I'm using Angular 5.2 with Auth0 for authentication. The login is done on a hosted login page by Auth0. That page redirects to my callback page myapp.com/login-callback in my Angular app.

Auth0 hands over some tokens via the hash in the url. So it redirects to

myapp.com/login-callback#access_token=123456789

Now comes the problem.. Since I changed my project to Angular-CLI and updated it from 5.1 to 5.2 Angular encodes the hash fragment, so that it becomes

myapp.com/login-callback#access_token%3D123456789

The = is encoded to %3D

Therefore the auth0 parsing function doesn't work anymore.

How can I prevent Angular from encoding the hash fragment of the url? I use the default routing strategy (by path, not by hash).

user3745073
  • 105
  • 1
  • 1
  • 6

2 Answers2

2

We just ran into the same thing with Auth0, while it doesn't disable that "feature" of angular you can grab the fragment and pass it into auth0's parse hash function.

import { ActivatedRoute } from '@angular/router';
import { WebAuth } from 'auth0-js';

//...
  constructor(private route: ActivatedRoute, private auth0: WebAuth) {}

  public handleAuth() {
    //...
    this.route.fragment.subscribe((hash) => {
      // hash is decoded at this point

      this.auth0.parseHash({hash}, (e, data) => {
        // ...
Steven
  • 1,107
  • 1
  • 8
  • 21
0

Well Angular by default encodes your URL with encodeURIComponent(), but you can override it by writing a custom URI serializer.

Check this answer: angular 2 disable url encoding

Basically, you overwrite UriSeriaizer with your own custom one.

filipbarak
  • 1,835
  • 2
  • 17
  • 28