【发布时间】:2021-05-31 18:15:07
【问题描述】:
我正在用nestJS 中的护照实施linkedin 登录策略。
我现在有一个按钮“使用linkedin登录”指向auth/linkedin。
@Get('auth/linkedin')
@UseGuards(AuthGuard('linkedin'))
async linkedinAuth(@Req() req) {
}
这很好用,将我带到linkedin登录页面并回击我的回调URL,即auth/linkedin/callback和code令牌查询字符串这是我无法弄清楚要做什么和如何做的地方返回linkedin用户
@Get('auth/linkedin/callback')
@UseGuards(AuthGuard('linkedin'))
linkedinCallBack(@Req() req) {
console.log(req)
return 'handle callback!';
}
Linkedin 护照策略:
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
const LinkedInAuthStrategy = require('passport-linkedin-oauth2').Strategy;
@Injectable()
export class LinkedinStrategy extends PassportStrategy(LinkedInAuthStrategy) {
constructor(
) {
super({
clientID: 'abcd123',
clientSecret: 'abcd123',
callbackURL: 'http://localhost:5000/auth/linkedin/callback',
scope: ['r_emailaddress', 'r_liteprofile'],
}, function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
console.log(profile);
return done(null, profile);
});
})
}
}
注意:我将这个package 用于linkedin 护照策略
问题:如何使用
@UseGuards进一步处理回调,并返回LinkedIn 用户?
【问题讨论】:
标签: javascript node.js passport.js linkedin nestjs