【问题标题】:Authentication using linkedin in a mean stack application在平均堆栈应用程序中使用linkedin进行身份验证
【发布时间】:2021-07-18 06:16:06
【问题描述】:

所以我一直在尝试在我的应用程序中实现 使用linkedin 登录,但我在网上找不到任何可以告诉我从 A 到 Z 的步骤的东西 我实现了 backendfrontend separateley,但是,我不知道如何将它们链接在一起

在后台,我用的是passportjs

这就是我到目前为止所做的:

前端

app.component.html

<button click="loginWithLinkedin()">Linkedin</button>

app.component.ts

window.location.href = `https://www.linkedin.com/uas/oauth2/authorization?response_type=code&state=true&client_id=${environment.LINKEDIN_API_KEY}&redirect_uri=${environment.LINKEDIN_REDIRECT_URL}&scope=${environment.LINKEDIN_SCOPE}`;

redirect.component.ts

const linkedInToken = this.route.snapshot.queryParams["code"];
this.http.get('http://localhost:3000/user/auth/linkedin',
 { params: { token: linkedinToken }}).subscribe(res => {
        console.log(res);
 });

后台

passport.use(new LinkedInStrategy({
      clientID: LINKEDIN_CLIENT_ID,
      clientSecret: LINKEDIN_CLIENT_SECRET,
      callbackURL: "http://127.0.0.1:8000/user/auth/linkedin/callback",
      scope: ['r_emailaddress', 'r_basicprofile'],
      passReqToCallback: true
    },
    function (req, accessToken, refreshToken, profile, done) {
      req.session.accessToken = accessToken;
      process.nextTick(function () {
        return done(null, profile);
      });
    }));


linkedinRouter.route('/auth/linkedin')
    .get(passport.authenticate('linkedin', { state: 'SOME STATE'  }),
    function(req, res){
        // The request will be redirected to LinkedIn for authentication, so this
        // function will not be called.
    });

linkedinRouter.route('/auth/linkedin/callback')
    .get( passport.authenticate('linkedin', { failureRedirect: '/' }),
        function (req, res) {
            return res.send('hello');
    });

我不明白护照如何工作,也不明白如何链接后端和前端。 我不知道这是否是实现linkedin认证的正确方法

如果你有任何可以指导的文章,或者如果你能纠正这真的有帮助,我已经被困了几天了。

非常感谢

【问题讨论】:

    标签: node.js angular authentication passport.js linkedin-api


    【解决方案1】:

    如果我提出问题的方式不好或者我不知道如何提出问题,我深表歉意。然而,我设法让它发挥作用,我写了一篇关于它的中篇文章。 这是链接: https://nour-karoui.medium.com/linkedin-authentication-for-a-mean-stack-application-bd8542b2dc7f

    我希望它可以帮助那里的人!

    【讨论】:

      猜你喜欢
      • 2015-03-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2018-12-20
      • 2011-06-27
      • 2012-06-10
      • 2013-09-13
      • 1970-01-01
      相关资源
      最近更新 更多