# oidc-client-node

> OpenID Connect (OIDC) node.js library

Latest version **1.0.10** (published 2016-04-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install oidc-client-node
pnpm add oidc-client-node
yarn add oidc-client-node
bun add oidc-client-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2016-04-11 |
| First published | 2015-07-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+15 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | edwinf |

## Links

- npm: https://www.npmjs.com/package/oidc-client-node
- Repository: https://github.com/edwinf/oidc-client-node
- Homepage: https://github.com/edwinf/oidc-client-node#readme
- Issues: https://github.com/edwinf/oidc-client-node/issues
- npm.io page: https://npm.io/package/oidc-client-node

## Dependencies (6)

- [url](https://npm.io/package/url.md) ^0.10.3
- [cookies](https://npm.io/package/cookies.md) ^0.5.0
- [bluebird](https://npm.io/package/bluebird.md) ^2.9.34
- [crypto-js](https://npm.io/package/crypto-js.md) ^3.1.5
- [jsrsasign](https://npm.io/package/jsrsasign.md) ^4.8.3
- [request-promise](https://npm.io/package/request-promise.md) ^0.4.2

## Recent versions

- 1.0.10 (latest) — 2016-04-11
- 1.0.11-beta2 (beta) — 2016-05-28
- 1.0.11-beta1 — 2016-05-28
- 1.0.10-beta1 — 2016-05-28
- 1.0.9 — 2015-10-13
- 1.0.8 — 2015-10-13
- 1.0.7 — 2015-09-27
- 1.0.6 — 2015-09-25
- 1.0.5 — 2015-08-26
- 1.0.4 — 2015-08-06
- 1.0.3 — 2015-07-27
- 1.0.2 — 2015-07-24
- 1.0.1 — 2015-07-24
- 1.0.0 — 2015-07-24

## README

# oidc-client

OpenID Connect (OIDC) client server side library

## Install
`$ npm install oidc-client-node`

## Configuration Options

 ```javascript
var oidcConfig = {
  scope: 'profile roles',
  client_id: 'implicit_client',
  callbackURL: '/auth/oidc/callback', // callback url, can be absolute or relative
  authority: 'https://localhost:50000/core'; //'--insert-your-openid-provider-domain-name-here--',
  response_type: "id_token token", 
  response_mode: "form_post",
  scopeSeparator: ' ',
  verbose_logging: true,
  httpSettings: { strictSSL = true } // optional http settings for Request
};
```

## Local options

You can also set options on a per request basis and have those options merged in. For example:

```javascript
var localOptions = {
  callbackURL: '/auth/oidc/callback', 
  acr_values: "tenant:12"
};
    
var oidcClient = new OidcClient(req, res, oidcConfig);

oidcClient.mergeRequestOptions(req, localOptions);

**Note: You are currently required to merge request options (even if they are empty), otherwise the client may not work appropriately.**
```
 
## Implicit Flow Configuration Example
 
 ```javascript
var oidcConfig = {
  scope: 'profile roles',
  client_id: 'implicit_client',
  callbackURL: '/auth/oidc/callback',
  authority: 'https://localhost:50000/core';
  response_type: "id_token token", 
  response_mode: "form_post",
  scopeSeparator: ' ',
  verbose_logging: true
};
```

## Code Flow Configuration Example
 
 ```javascript
var oidcConfig = {
  scope: 'profile roles offline_access', // offline is not required for code flow, but is typically used in this flow to get refresh tokens
  client_id: 'implicit_client',
  callbackURL: '/auth/oidc/callback',
  authority: 'https://localhost:50000/core';
  response_type: "code", 
  response_mode: "form_post",
  scopeSeparator: ' ',
  verbose_logging: true
};
```

## Wiring up your routes

Wire up your routes (this example uses req.body which was based on express / body parser) 

```javascript
app.get('/auth/oidc/login',
  function (req, res) {
    
    var oidcClient = new OidcClient(req, res, oidcConfig);
        
    var tokenRequest = oidcClient.createTokenRequestAsync();
    
    tokenRequest.then(function (results) {
      console.log('about to redirect');
      res.redirect(results.url);  
    }).catch(function(error){
        console.log('error generating redirect url: ' + error);
    });
});

app.post(/auth/oidc/callback,
  function (req, res) {
    
    var oidcClient = new OidcClient(req, res, oidcConfig);
    
    var tokenResponse = oidcClient.processResponseAsync(req.body);
    
    tokenResponse.then(function (results) {
      console.log(results);
    }).catch(function(error) {
        console.log('error parsing token response: ' + error);
    });
    
    console.log('Made it to the end of the response function');
});
```

## Response Example

Here's an example of all the possible data in a response. What values you get back will dependent on the flow as well as the identity provider you are integrating with.

```javascript
{
  "profile": {
    "sub": "1",
    "name": "User"
  },
  "id_token": "613bfdfc867a4a838784965582aecfbb",
  "access_token": "b976452d0cb94ced8825f3297bed2628",
  "refresh_token": "62fd0a32fbc0496ab21e48835343b852",
  "expires_in": 360
}
```

## Refreshing a token

Refreshing a token is very similar to the other scenarios, it still requires configuration of the oidc client. The main difference is that no call-back to a route occurs.

### Refresh Token Configuration Example

 ```javascript
var oidcConfig = {
  scope: 'profile roles',
  client_id: 'clientcreds_client',
  client_secret: 'your_secret',
  callbackURL: '/auth/oidc/callback',
  authority: 'https://localhost:50000/core';
  scopeSeparator: ' ',
  verbose_logging: true
};
```

### Refresh Token Request Example

```javascript
app.get('/token/refresh/', function(req, res) {
  var oidcClient = new OidcClient(req, res, oidcConfig);
  oidcClient.mergeRequestOptions(req, {});
  
  var refreshToken = getRefreshToken(); // get the current refresh token you have persisted somewhere
  
  oidcClient.refreshAccessTokenAsync(refreshToken).then(function (tokenResponse) {
    handleTokenResponse(tokenResponse); // do something with the token you received
    res.redirect('/');
  });
});
```

---
_Source: https://npm.io/package/oidc-client-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
