Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/flower-of-the-bridges/client-credentials-js

Client Credentials OAuth 2.0 flow written in plain Javascript.
https://github.com/flower-of-the-bridges/client-credentials-js

client-credentials client-credentials-flow javascript oauth2

Last synced: 7 days ago
JSON representation

Client Credentials OAuth 2.0 flow written in plain Javascript.

Awesome Lists containing this project

README

        

# Client Credentials JS

Client Credentials OAuth2.0 flow written in plain Javascript.

## Install

```
npm i --save client-credentials-js
```

## Usage

```js
const ClientCredentials = require('client-credentials-js')
// create client
const clientCredentials = new ClientCredentials({
client: {
id: '',
secret: '',
// additional parameters (scope, audience, etc...)
},
auth: {
authorizePath: '/oauth/token',
refreshPath: 'refresh',
host: MOCK_CONFIG.HOST
}
})
// get token
const token = await clientCredentials.getToken()

console.log(token.access_token) // some jwt...
console.log(token.expires_in) // 3600 (seconds)
console.log(token.token_type) // 'Bearer'

// check if token is expired
console.log(token.isExpired()) // true

// return token if not expired, otherwise refresh
const token = await clientCredentials.getTokenOrRefresh()
```

### Examples

The following object represents allowed client configurations that can be used for several identity providers.

#### Microsoft

```json
{
"client": {
"id": "",
"secret": "",
"scope": "default"
}
}
```

#### Auth0

```json
{
"client": {
"id": "",
"secret": "",
"audience": "default"
}
}
```