我正在使用这个github项目https://github.com/openiddict/openiddict-core,非常好用。但是当用户使用外部身份提供者时,我卡住了,不知道应该采取什么步骤或如何实现它,例如,我将使用谷歌作为示例。
我有一个运行中的angular2应用程序和一个aspnet core webAPI。所有本地登录都很完美,我调用
现在我需要将谷歌作为外部身份提供者实现。我按照此处的所有步骤来实现谷歌登录按钮。当用户登录时,这会打开一个弹出窗口。这是我为我的谷歌按钮创建的代码。
现在我从谷歌获得了一个idToken。谷歌页面上找到的下一步(此处)说我需要验证谷歌accessToken,这是可行的,但是如何交换我从谷歌获得的accessToken,并创建本地accessToken以在我的应用程序中使用?
我有一个运行中的angular2应用程序和一个aspnet core webAPI。所有本地登录都很完美,我调用
connect/token
并返回一个accessToken。现在我需要将谷歌作为外部身份提供者实现。我按照此处的所有步骤来实现谷歌登录按钮。当用户登录时,这会打开一个弹出窗口。这是我为我的谷歌按钮创建的代码。
// Angular hook that allows for interaction with elements inserted by the
// rendering of a view.
ngAfterViewInit() {
// check if the google client id is in the pages meta tags
if (document.querySelector("meta[name='google-signin-client_id']")) {
// Converts the Google login button stub to an actual button.
gapi.signin2.render(
'google-login-button',
{
"onSuccess": this.onGoogleLoginSuccess,
"scope": "profile",
"theme": "dark"
});
}
}
onGoogleLoginSuccess(loggedInUser) {
let idToken = loggedInUser.getAuthResponse().id_token;
// here i can pass the idToken up to my server and validate it
}
现在我从谷歌获得了一个idToken。谷歌页面上找到的下一步(此处)说我需要验证谷歌accessToken,这是可行的,但是如何交换我从谷歌获得的accessToken,并创建本地accessToken以在我的应用程序中使用?