@dmapper/passport-linkedin-oauth2

中文文档
1.0.1发布于 2022/08/11MITCommonJS近 30 天下载 3689

LinkedIn OAuth2 API v2 的护照

中文使用文档
文档目录6 节
  1. 安装
  2. 使用量
  3. 自动处理 state 段落
  4. 问题报告
  5. 作者
  6. 许可证

很简单 护照 linkedIn OAuth2 策略,与 lite profile 工作.

此分叉执行可选的回调函数, 用于通过客户端 ID 和 secret 每次在认证前直接访问 Oauth2 。 此函数称为 带有请求对象.

var LinkedInStrategy = require('@dmapper/passport-linkedin-oauth2').Strategy;

passport.use(new LinkedInStrategy({
    getClient: async function(req) {
      // some possible async operations
      // ...
      return {
        id: '#####',
        secret: '#####'
      }
    },
    callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
    scope: ['r_emailaddress', 'r_liteprofile'],
  },
  function(accessToken, refreshToken, profile, cb) {
    // To keep the example simple, the user's LinkedIn profile is returned to
    // represent the logged-in user. In a typical application, you would want
    // to associate the LinkedIn account with a user record in your database,
    // and return that user instead.
    return done(null, profile);
  }
));

====================================================================================

安装

npm 安装 @dmapper/ passport- connectionin-oaut2

使用量

登记战略

var LinkedInStrategy = require('@dmapper/passport-linkedin-oauth2').Strategy;

passport.use(new LinkedInStrategy({
  clientID: LINKEDIN_KEY,
  clientSecret: LINKEDIN_SECRET,
  callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
  scope: ['r_emailaddress', 'r_liteprofile'],
}, function(accessToken, refreshToken, profile, done) {
  // asynchronous verification, for effect...
  process.nextTick(function () {
    // To keep the example simple, the user's LinkedIn profile is returned to
    // represent the logged-in user. In a typical application, you would want
    // to associate the LinkedIn account with a user record in your database,
    // and return that user instead.
    return done(null, profile);
  });
}));

然后认证为:

app.get('/auth/linkedin',
  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.
  });

登录回调 :

app.get('/auth/linkedin/callback', passport.authenticate('linkedin', {
  successRedirect: '/',
  failureRedirect: '/login'
}));

见 这个 详细内容请访问 LinkedIn API.

自动处理 state 段落

这个 state param用于防止CSRF攻击,并且 aPI 链接。您可以要求护照处理发送和验证 state 通过参数 state: true 作为该战略的一个选择:

var LinkedInStrategy = require('@dmapper/passport-linkedin-oauth2').Strategy;

passport.use(new LinkedInStrategy({
  clientID: LINKEDIN_KEY,
  clientSecret: LINKEDIN_SECRET,
  callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
  scope: ['r_emailaddress', 'r_liteprofile'],
  state: true
}, function(accessToken, refreshToken, profile, done) {
  // asynchronous verification, for effect...
  process.nextTick(function () {
    // To keep the example simple, the user's LinkedIn profile is returned to
    // represent the logged-in user. In a typical application, you would want
    // to associate the LinkedIn account with a user record in your database,
    // and return that user instead.
    return done(null, profile);
  });
}));

然后认证为:

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

问题报告

如果您找到错误或有特性请求, 请在此寄存器问题节中报告 。 请不要在公共 GitHub 问题跟踪器上报告安全漏洞 。 这个 负责任的披露程序 详细说明披露安全问题的程序.

作者

自动 0

许可证

这个项目根据麻省理工学院的许可证获得许可。 见 自由主义 需要更多信息的文件.

版本与发布记录

@dmapper/passport-linkedin-oauth2 共发布 2 个版本,首次发布于 2022/08/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2022/08/114 年前
1.0.02022/08/094 年前

关于 @dmapper/passport-linkedin-oauth2 的常见问题

@dmapper/passport-linkedin-oauth2 是什么?

LinkedIn OAuth2 API v2 的护照

如何安装 @dmapper/passport-linkedin-oauth2?

在项目目录运行 npm install @dmapper/passport-linkedin-oauth2,或使用 pnpm add / yarn add / bun add。

@dmapper/passport-linkedin-oauth2 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dmapper__passport-linkedin-oauth2 是否存在。

@dmapper/passport-linkedin-oauth2 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dmapper/passport-linkedin-oauth2 可以商用吗?

@dmapper/passport-linkedin-oauth2 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dmapper/passport-linkedin-oauth2 的下载量有多少?

根据 npm 官方下载统计,@dmapper/passport-linkedin-oauth2 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,689 次,日均约 123 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dmapper/passport-linkedin-oauth2 还在维护吗?

最新版本 1.0.1 发布于 2022/08/11(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/08/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。