angular - Fetch #access_token from URL -


my landing url after sso login is:

http://localhost:4200/login#access_token=f1946707a99f5be17cd639c49ed46e22af778a473aa1d93220d157d1a9b9ff83&token_type=bearer&expires_in=7200

now, how can fetch #access_token value url?

use function provided below token value

//get token value url //you can use window.location.href or pass value please let token: string = getparameterbyname("access_token", location.href);  public getparameterbyname(name: string, url: string): string {     if (!url) url = window.location.href;     name = name.replace(/[\[\]]/g, "\\$&");     let regex = new regexp("[?&]" + name + "(=([^&#]*)|&|#|$)"),                 results = regex.exec(url);     if (!results) return null;     if (!results[2]) return '';         return decodeuricomponent(results[2].replace(/\+/g, " ")); } 

if want value in routing event

in component imports router

this.router.events     .filter(event => event instanceof navigationend)     .map(() => this.activatedroute)     .map(route => {         while (route.firstchild) route = route.firstchild;         return route;     }).filter(route => route.outlet === 'primary')       .mergemap(route => route.data)       .subscribe((event) => {           //use code here value        } ); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -