@dmapper/passport-linkedin-oauth2

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

Passport for LinkedIn OAuth2 API v2

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Auto-handle state param
  4. Issue Reporting
  5. Author
  6. License

A simple Passport strategy for LinkedIn OAuth2 that works with lite profile.

This fork implements optional callback function that can be used to pass client id and secret to initialise oauth2 each time directly before an authentication. This function is called with the request object.

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);
  }
));

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

Install

npm install @dmapper/passport-linkedin-oauth2

Usage

Register the strategy

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);
  });
}));

and then authenticate as:

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.
  });

the login callback:

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

See this for details on LinkedIn API.

Auto-handle state param

The state param is used to prevent CSRF attacks, and is required by the LinkedIn API. You can ask Passport to handle the sending and validating of the state parameter by passing state: true as an option to the strategy:

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);
  });
}));

and then authenticate as:

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.
  });

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

版本与发布记录

@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 是什么?

Passport for 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 和提交记录判断。