{"id":28076753,"url":"https://github.com/jaredhanson/passport-openidconnect","last_synced_at":"2025-05-13T01:49:54.127Z","repository":{"id":41381457,"uuid":"8242651","full_name":"jaredhanson/passport-openidconnect","owner":"jaredhanson","description":"OpenID Connect authentication strategy for Passport and Node.js.","archived":false,"fork":false,"pushed_at":"2024-08-08T19:28:15.000Z","size":232,"stargazers_count":200,"open_issues_count":51,"forks_count":180,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-13T01:49:45.311Z","etag":null,"topics":["oauth2","openid-connect","passport"],"latest_commit_sha":null,"homepage":"https://www.passportjs.org/packages/passport-openidconnect/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=passport-openidconnect\u0026utm_content=about","language":"JavaScript","has_issues":true,"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/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jaredhanson"}},"created_at":"2013-02-16T22:40:03.000Z","updated_at":"2025-05-09T00:58:15.000Z","dependencies_parsed_at":"2024-02-08T20:42:47.955Z","dependency_job_id":null,"html_url":"https://github.com/jaredhanson/passport-openidconnect","commit_stats":{"total_commits":305,"total_committers":16,"mean_commits":19.0625,"dds":"0.12131147540983611","last_synced_commit":"101e0f3739157e6f9f0f027f4c8ee4553d6196ff"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-openidconnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-openidconnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-openidconnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-openidconnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/passport-openidconnect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856616,"owners_count":21974576,"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","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":["oauth2","openid-connect","passport"],"created_at":"2025-05-13T01:49:53.565Z","updated_at":"2025-05-13T01:49:54.121Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jaredhanson"],"categories":[],"sub_categories":[],"readme":"# passport-openidconnect\n\n[Passport](https://www.passportjs.org/) strategy for authenticating\nwith [OpenID Connect](https://openid.net/connect/).\n\nThis module lets you authenticate using OpenID Connect in your Node.js\napplications.  By plugging into Passport, OpenID Connect-based sign in can be\neasily and unobtrusively integrated into any application or framework that\nsupports [Connect](https://github.com/senchalabs/connect#readme)-style\nmiddleware, including [Express](https://expressjs.com/).\n\n\u003cdiv align=\"center\"\u003e\n\n:heart: [Sponsors](https://www.passportjs.org/sponsors/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=passport-openidconnect\u0026utm_content=nav-sponsors)\n\n\u003c/div\u003e\n\n## Install\n\n```sh\n$ npm install passport-openidconnect\n```\n\n## Usage\n\n#### Configure Strategy\n\nThe OpenID Connect authentication strategy authenticates users using their\naccount at an OpenID Provider (OP).  The strategy needs to be configured with\nthe provider's endpoints, as well as a client ID and secret that has been issued\nby the provider to the app.  Consult the provider's documentation for the\nlocations of these endpoints and instructions on how to register a client.\n\nThe strategy takes a `verify` function as an argument, which accepts `issuer`\nand `profile` as arguments.  `issuer` is set to an identifier for the OP.\n`profile` contains the user's [profile information](https://www.passportjs.org/reference/normalized-profile/)\nstored in their account at the OP.  When authenticating a user, this strategy\nuses the OpenID Connect protocol to obtain this information via a sequence of\nredirects and back-channel HTTP requests to the OP.\n\nThe `verify` function is responsible for determining the user to which the\naccount at the OP belongs.  In cases where the account is logging in for the\nfirst time, a new user record is typically created automatically.  On subsequent\nlogins, the existing user record will be found via its relation to the OP\naccount.\n\nBecause the `verify` function is supplied by the application, the app is free to\nuse any database of its choosing.  The example below illustrates usage of a SQL\ndatabase.\n\n```js\nvar OpenIDConnectStrategy = require('passport-openidconnect');\n\npassport.use(new OpenIDConnectStrategy({\n    issuer: 'https://server.example.com',\n    authorizationURL: 'https://server.example.com/authorize',\n    tokenURL: 'https://server.example.com/token',\n    userInfoURL: 'https://server.example.com/userinfo',\n    clientID: process.env['CLIENT_ID'],\n    clientSecret: process.env['CLIENT_SECRET'],\n    callbackURL: 'https://client.example.org/cb'\n  },\n  function verify(issuer, profile, cb) {\n    db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [\n      issuer,\n      profile.id\n    ], function(err, cred) {\n      if (err) { return cb(err); }\n      \n      if (!cred) {\n        // The account at the OpenID Provider (OP) has not logged in to this app\n        // before.  Create a new user account and associate it with the account\n        // at the OP.\n        db.run('INSERT INTO users (name) VALUES (?)', [\n          profile.displayName\n        ], function(err) {\n          if (err) { return cb(err); }\n          \n          var id = this.lastID;\n          db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [\n            id,\n            issuer,\n            profile.id\n          ], function(err) {\n            if (err) { return cb(err); }\n            var user = {\n              id: id,\n              name: profile.displayName\n            };\n            return cb(null, user);\n          });\n        });\n      } else {\n        // The account at the OpenID Provider (OP) has previously logged in to\n        // the app.  Get the user account associated with the account at the OP\n        // and log the user in.\n        db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, row) {\n          if (err) { return cb(err); }\n          if (!row) { return cb(null, false); }\n          return cb(null, row);\n        });\n      }\n    });\n  }\n));\n```\n\n#### Define Routes\n\nTwo routes are needed in order to allow users to log in with their account at an\nOP.  The first route redirects the user to the OP, where they will authenticate:\n\n```js\napp.get('/login', passport.authenticate('openidconnect'));\n```\n\nThe second route processes the authentication response and logs the user in,\nwhen the OP redirects the user back to the app:\n\n```js\napp.get('/cb',\n  passport.authenticate('openidconnect', { failureRedirect: '/login', failureMessage: true }),\n  function(req, res) {\n    res.redirect('/');\n  });\n```\n\n## Examples\n\n* [todos-express-openidconnect](https://github.com/passport/todos-express-openidconnect)\n\n  Illustrates how to use the OpenID Connect strategy within an Express\n  application.\n\n* [todos-express-auth0](https://github.com/passport/todos-express-auth0)\n\n  Illustrates how to use the OpenID Connect strategy to integrate with [Auth0](https://auth0.com/)\n  in an Express application.  For developers new to Passport and getting\n  started, a [tutorial](https://www.passportjs.org/tutorials/auth0/) is\n  available.\n\n## License\n\n[The MIT License](https://opensource.org/licenses/MIT)\n\nCopyright (c) 2011-2022 Jared Hanson \u003c[https://www.jaredhanson.me/](https://www.jaredhanson.me/)\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-openidconnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fpassport-openidconnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-openidconnect/lists"}