gpt4 book ai didi

angular - Auth0 SSO Angular 返回 WebpackOk

转载 作者:行者123 更新时间:2023-12-05 07:41:47 24 4
gpt4 key购买 nike

我正在开发一个使用 Auth0 来处理用户的 Angular 应用程序。我期待有一种方法可以同时使用两个客户端。如果我有两个 JWT 没关系。我在 Auth0 中看到了有关单点登录 (SSO) 的信息。我已经实现了它,但它不起作用。

@Injectable()
export class AuthService {
auth0js = new auth0.WebAuth({
domain: 'domain.com',
clientID: 'clientID',
scope: 'openid name picture groups permissions roles',
responseType: 'token id_token',
redirectUri: 'http://localhost:4200'
});

auth0js2 = new auth0.WebAuth({
domain: 'domain2.com',
clientID: 'clientID2',
scope: 'openid name picture groups permissions roles',
responseType: 'token id_token',
redirectUri: 'http://localhost:4200'
});

profile: any;
profile$ = new BehaviorSubject<any>(this.profile);

constructor(
private notificationService: NotificationService,
private router: Router,
private _ngZone: NgZone){
}

public login(): void {
this.auth0js.authorize();
}

public handleAuthentication(): void {
const self = this;
self.auth0js.parseHash({ _idTokenVerification: false }, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
window.location.hash = '';
self.setSession(authResult);
self._ngZone.runOutsideAngular(() => {
self.renew();
});
} else if (err) {
self.router.navigate(['/home']);
console.log(err);
}
});
}

renew() {
const self = this;
self.auth0js2.renewAuth({
audience: 'domain.com/api/v2/',
scope: 'openid name picture groups permissions roles',
redirectUri: 'localhost:4200',
usePostMessage: true}, function (err, authResult) {
if (err) {
alert(`Could not get a new token using silent authentication (${err.error}). Redirecting to login page...`);
self.auth0js2.authorize();
} else {
console.log('AUTH', authResult);
self.setSession2(authResult);
}
});
}

private setSession(authResult): void {
const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
localStorage.setItem('access_token', authResult.accessToken);
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('expires_at', expiresAt);
}

private setSession2(authResult): void {
// Here I've got {type: "webpackOk", data: undefined} as authResult
// Set the time that the access token will expire at
const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
localStorage.setItem('access_token2', authResult.accessToken);
localStorage.setItem('id_token2', authResult.idToken);
localStorage.setItem('expires_at2', expiresAt);
}
}

当我进行静默身份验证时,我收到以下响应:

{type: "webpackOk": data: undefined}

最佳答案

它是这样工作的

   setTimeout(function () {
iframe.contentWindow.postMessage(data, '*')
}, 1000)

关于angular - Auth0 SSO Angular 返回 WebpackOk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45142775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com