# @dmapper/passport-linkedin-oauth2 中文文档

规范地址：https://npmcn.com/package/%40dmapper/passport-linkedin-oauth2/

版本：1\.0\.1
npm 元数据更新时间：2026-05-01T14:28:48.526Z
中文译文更新时间：2026-11-12T12:59:12.039Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40dmapper/passport-linkedin-oauth2
原文对照：https://npmcn.com/package/%40dmapper/passport-linkedin-oauth2/?lang=original
项目主页：https://github.com/zheoreh/passport-linkedin-oauth2#readme
源码仓库：https://github.com/zheoreh/passport-linkedin-oauth2

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：27.5 kB，13 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：1 个
- 首次发布：2022-08-08T16:04:47.151Z
- 最新版本发布：2022-08-11T10:56:38.340Z
- 近 30 天下载量：3689（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

LinkedIn OAuth2 API v2 的护照

## 安装

```sh
npm install @dmapper/passport-linkedin-oauth2
```

也可以使用：`pnpm add @dmapper/passport-linkedin-oauth2`、`yarn add @dmapper/passport-linkedin-oauth2`、`bun add @dmapper/passport-linkedin-oauth2`

## README

很简单 [护照](http://passportjs.org/) linkedIn OAuth2 策略,与 lite profile 工作.

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

```js
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

## 使用量

登记战略

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

然后认证为:

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

登录回调 :

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

见 [这个](https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context?trk=eml_mktg_gco_dev_api_comms) 详细内容请访问 LinkedIn API.

## 自动处理 `state` 段落

这个 `state` param用于防止CSRF攻击,并且 [aPI 链接](https://developer.linkedin.com/documents/authentication)。您可以要求护照处理发送和验证 `state` 通过参数 `state: true` 作为该战略的一个选择:

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

然后认证为:

```javascript
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 问题跟踪器上报告安全漏洞 。 这个 [负责任的披露程序](https://auth0.com/whitehat) 详细说明披露安全问题的程序.

## 作者

[自动 0](https://npmcn.com/package/%40dmapper/passport-linkedin-oauth2/auth0.com)

## 许可证

这个项目根据麻省理工学院的许可证获得许可。 见 [自由主义](https://npmcn.com/package/%40dmapper/passport-linkedin-oauth2/LICENSE) 需要更多信息的文件.

## 常见问题

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

