Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/flower-of-the-bridges/client-credentials-js
- Owner: flower-of-the-bridges
- License: mit
- Created: 2023-12-05T09:17:04.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2023-12-19T11:05:38.000Z (11 months ago)
- Last Synced: 2024-09-21T16:29:12.317Z (about 2 months ago)
- Topics: client-credentials, client-credentials-flow, javascript, oauth2
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/client-credentials-js
- Size: 251 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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"
}
}
```