{"id":13487584,"url":"https://github.com/eggjs/egg-passport","last_synced_at":"2025-10-14T14:17:50.244Z","repository":{"id":56073875,"uuid":"65813632","full_name":"eggjs/egg-passport","owner":"eggjs","description":"passport plugin for egg","archived":false,"fork":false,"pushed_at":"2022-12-18T03:26:21.000Z","size":42,"stargazers_count":108,"open_issues_count":3,"forks_count":25,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-10-05T15:46:43.697Z","etag":null,"topics":["egg","egg-passport","egg-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-16T11:10:25.000Z","updated_at":"2025-06-14T15:16:15.000Z","dependencies_parsed_at":"2023-01-29T18:30:34.426Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-passport","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-passport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-passport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-passport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-passport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-passport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-passport/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-passport/sbom","scorecard":{"id":368755,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-passport","commit":"6a31dc7b05e6abd9b3208d26a6dda3bb3cbd84d7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.7,"checks":[{"name":"Code-Review","score":5,"reason":"Found 9/17 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":9,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql.yml:16","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql.yml:17","Warn: no topLevel permission defined: .github/workflows/codeql.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-passport/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-passport/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-passport/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-passport/codeql.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T12:29:35.635Z","repository_id":56073875,"created_at":"2025-08-18T12:29:35.635Z","updated_at":"2025-08-18T12:29:35.635Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017361,"owners_count":26086052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["egg","egg-passport","egg-plugin"],"created_at":"2024-07-31T18:01:00.860Z","updated_at":"2025-10-14T14:17:50.206Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["插件"],"readme":"# egg-passport\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-passport.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-passport\n[travis-image]: https://img.shields.io/travis/eggjs/egg-passport.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-passport\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-passport.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-passport?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-passport.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-passport\n[snyk-image]: https://snyk.io/test/npm/egg-passport/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-passport\n[download-image]: https://img.shields.io/npm/dm/egg-passport.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-passport\n\npassport plugin for egg, base on [passportjs](http://passportjs.org).\n\n## Install\n\n```bash\n$ npm i egg-passport\n```\n\n## Usage\n\n### enable passport plugin\n\n```js\n// config/plugin.js\nexports.passport = {\n  enable: true,\n  package: 'egg-passport',\n};\n```\n\n### Using Github and Twitter strategy\n\n```js\n// config/config.default.js\nexports.passportGithub = {\n  key: 'my oauth2 clientID',\n  secret: 'my oauth2 clientSecret',\n};\n\nexports.passportTwitter = {\n  key: 'my oauth1 consumerKey',\n  secret: 'my oauth1 consumerSecret',\n};\n```\n\n### Authenticate Requests\n\nUse `app.passport.mount(strategy[, options])`, specifying the `'github'` and `'twitter'` strategy, to authenticate requests.\n\n```js\n// app/router.js\nmodule.exports = app =\u003e {\n  app.get('/', 'home.index');\n\n  // authenticates routers\n  app.passport.mount('github');\n  // this is a passport router helper, it's equal to the below codes\n  //\n  // const github = app.passport.authenticate('github');\n  // app.get('/passport/github', github);\n  // app.get('/passport/github/callback', github);\n\n  // custom options.login url and options.successRedirect\n  app.passport.mount('twitter', {\n    loginURL: '/account/twitter',\n    // auth success redirect to /\n    successRedirect: '/',\n  });\n};\n```\n\n### Verify and store user\n\nUse `app.passport.verify(async (ctx, user) =\u003e {})` hook:\n\n```js\n// app.js\nmodule.exports = app =\u003e {\n  app.passport.verify(async (ctx, user) =\u003e {\n    // check user\n    assert(user.provider, 'user.provider should exists');\n    assert(user.id, 'user.id should exists');\n\n    // find user from database\n    //\n    // Authorization Table\n    // column   | desc\n    // ---      | --\n    // provider | provider name, like github, twitter, facebook, weibo and so on\n    // uid      | provider unique id\n    // user_id  | current application user id\n    const auth = await ctx.model.Authorization.findOne({\n      uid: user.id,\n      provider: user.provider,\n    });\n    const existsUser = await ctx.model.User.findOne({ id: auth.user_id });\n    if (existsUser) {\n      return existsUser;\n    }\n    // call user service to register a new user\n    const newUser = await ctx.service.user.register(user);\n    return newUser;\n  });\n};\n```\n\n## How to develop an `egg-passport-${provider}` plugin\n\nSee example: [egg-passport-twitter](https://github.com/eggjs/egg-passport-twitter).\n\n- Plugin dependencies on [egg-passport](https://github.com/eggjs/egg-passport) to use `app.passport` APIs.\n\n```json\n// package.json\n{\n  \"eggPlugin\": {\n    \"name\": \"passportTwitter\",\n    \"dependencies\": [\n      \"passport\"\n    ]\n  },\n}\n```\n\n- Define config and set default values\n\n**Must use `key` and `secret` instead of `consumerKey|clientID` and `consumerSecret|clientSecret`.**\n\n```js\n// config/config.default.js\nexports.passportTwitter: {\n  key: '',\n  secret: '',\n  callbackURL: '/passport/twitter/callback',\n};\n```\n\n- Init `Strategy` in `app.js` and format user in `verify callback`\n\n```js\n// app.js\nconst debug = require('debug')('egg-passport-twitter');\nconst assert = require('assert');\nconst Strategy = require('passport-twitter').Strategy;\n\nmodule.exports = app =\u003e {\n  const config = app.config.passportTwitter;\n  // must set passReqToCallback to true\n  config.passReqToCallback = true;\n  assert(config.key, '[egg-passport-twitter] config.passportTwitter.key required');\n  assert(config.secret, '[egg-passport-twitter] config.passportTwitter.secret required');\n  // convert to consumerKey and consumerSecret\n  config.consumerKey = config.key;\n  config.consumerSecret = config.secret;\n\n  // register twitter strategy into `app.passport`\n  // must require `req` params\n  app.passport.use('twitter', new Strategy(config, (req, token, tokenSecret, params, profile, done) =\u003e {\n    // format user\n    const user = {\n      provider: 'twitter',\n      id: profile.id,\n      name: profile.username,\n      displayName: profile.displayName,\n      photo: profile.photos \u0026\u0026 profile.photos[0] \u0026\u0026 profile.photos[0].value,\n      token,\n      tokenSecret,\n      params,\n      profile,\n    };\n    debug('%s %s get user: %j', req.method, req.url, user);\n    // let passport do verify and call verify hook\n    app.passport.doVerify(req, user, done);\n  }));\n};\n```\n\n- That's all!\n\n## APIs\n\n### extent `application`\n\n- `app.passport.mount(strategy, options)`: Mount the login and the login callback routers to use the given `strategy`.\n- `app.passport.authenticate(strategy, options)`: Create a middleware that will authorize a third-party account using the given `strategy` name, with optional `options`.\n- `app.passport.verify(handler)`: Verify authenticated user\n- `app.passport.serializeUser(handler)`: Serialize user before store into session\n- `app.passport.deserializeUser(handler)`: Deserialize user after restore from session\n\n### extend `context`\n\n- `ctx.user`: get the current authenticated user\n- `ctx.isAuthenticated()`: Test if request is authenticated\n- `* ctx.login(user[, options])`: Initiate a login session for `user`.\n- `ctx.logout()`: Terminate an existing login session\n\n## Unit Tests\n\nThis plugin has includes some mock methods to helper you writing unit tests more conveniently.\n\n### `app.mockUser([user])`: Mock an authenticated user\n\n```js\nconst mm = require('egg-mock');\n\ndescribe('mock user demo', () =\u003e {\n  let app;\n  before(() =\u003e {\n    app = mm.app();\n    return app.ready();\n  });\n  after(() =\u003e app.close());\n\n  afterEach(mm.restore);\n\n  it('should show authenticated user info', () =\u003e {\n    app.mockUser();\n    return request(app.callback())\n      .get('/')\n      .expect(/user name: mock_name/)\n      .expect(200);\n  });\n});\n```\n\n### `app.mockUserContext([user])`: Mock a context instance with authenticated user\n\n```js\nit('should get authenticated user and call service', async () =\u003e {\n  const ctx = app.mockUserContext();\n  const result = await ctx.service.findUser({ id: ctx.user.id });\n  assert(result.user.id === ctx.user.id);\n});\n```\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-passport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-passport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-passport/lists"}