Angular 8-如何从回调路由中的URL获取数据

如何从keycloak服务器到我的授权组件获取access_token。 授权网址如下所示:

http://localhost:8081/auth/realms/external/protocol/openid-connect/auth?client_id=myapp&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth&response_type=token&scope=openid&nonce=test123

The callback url is in http://localhost:4200/auth , here is the component:

import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router';

@Component({
selector: 'app-auth',
templateUrl: './auth.component.html',
styleUrls: ['./auth.component.scss']
})
export class AuthComponent implements OnInit {

constructor(private route: ActivatedRoute) { }

ngOnInit() {
    console.log(this.route.snapshot);
    console.log(this.route.snapshot);
}

}

成功登录后,会从密钥斗篷中返回access_token,如下所示:

http://localhost:4200/auth#access_token=qwerty123&session_time=123456789

我的答案是,如何使其工作并获得access_token。

评论