gpt4 book ai didi

node.js - 如何在 MEAN 堆栈中实现社交登录?

转载 作者:IT老高 更新时间:2023-10-28 23:26:47 24 4
gpt4 key购买 nike

我已经在 Node JS 中成功实现了多个社交登录。

我坚持使用 MEAN 堆栈中的实现。

到目前为止我已经实现的流程:

第 1 步:

Angular 中的按钮。单击时,我在 Node 中调用一个 API,该 API 返回用户必须转发到的 OAuth URL。

第二步:

一旦用户输入正确的凭据,就会生成 access_token 并将其发送到 Node.js 中的回调 URL。

第三步:

无论是否生成了 access_token,我都需要向 Angular 发送回调。我不确定我应该如何将数据传递给 Angular Page。

这是正确的方法吗?

最佳答案

所以我自己正在做一个平均堆栈的社交媒体项目,我使用了 oauth.io,

https://github.com/oauth-io/oauth-js

它真的很容易使用和实现,你只需要知道如何在 Angular 中导入 npm 包。

linkedin HTML 组件

    <html>
<header>

</header>

<body>

<a (click)="linkedinConnector()" id="linkedin-button" class="btn btn-block btn-social btn-linkedin">
<i class="fa fa-linkedin"></i> Sign in with Linkedin
</a>

</body>
</html>

linkendin TS 组件

import { Component, OnInit } from '@angular/core';
import 'oauthio-web';


declare var OAuth: any;
@Component({
selector: 'app-linkedin-connector',
templateUrl: './linkedin-connector.component.html',
styleUrls: ['./linkedin-connector.component.css']
})

export class LinkedinConnectorComponent implements OnInit {

constructor(private api: ApiService) { }

ngOnInit() {}


public linkedinConnector() {
OAuth.initialize('OAUTH-IO PUBLIC KEY');

// Use popup for oauth
OAuth.popup('linkedin2').then(linkedin => {
console.log('linkedin:', linkedin.access_token);

linkedin.get('/v1/companies/[company-ID]/updates?format=json').then(data => {
//do with the data what you want
});
});
}

}

但是我使用弹出窗口而不是重定向。他们也有重定向,所以你可以使用那里的文档实现它
http://docs.oauth.io/

关于node.js - 如何在 MEAN 堆栈中实现社交登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52401796/

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