Skip to content

Commit

Permalink
feat(scheme/oauth2): add option to use IdToken instead of AccessToken (
Browse files Browse the repository at this point in the history
  • Loading branch information
sschadwick authored and pi0 committed Apr 5, 2018
1 parent 08299ea commit 554a042
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/schemes/oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ auth: {
token_type: 'Bearer',
redirect_uri: undefined,
client_id: 'SET_ME',
token_key: 'access_token'
}
}
}
Expand Down Expand Up @@ -55,6 +56,10 @@ Should be same as login page or relative path to welcome screen. ([example](http

**REQUIRED** - oauth2 client id.

### `token_key`

By default is set to `token_key: 'access_token'`. If you need to use the IdToken instead of the AccessToken, set this option to `token_key: 'id_token'`.

## Usage

```js
Expand Down
12 changes: 6 additions & 6 deletions lib/schemes/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export default class Oauth2Scheme {
const search = parseQuery(window.location.search.substr(1))
const parsedQuery = Object.assign({}, search, hash)

// accessToken
let accessToken = parsedQuery.access_token
// accessToken/idToken
let token = parsedQuery[this.options.token_key || 'access_token']

// -- Authorization Code Grant --
if (this.options.response_type === 'code' && parsedQuery.code) {
Expand All @@ -102,11 +102,11 @@ export default class Oauth2Scheme {
})

if (data.access_token) {
accessToken = data.access_token
token = data.access_token
}
}

if (!accessToken || !accessToken.length) {
if (!token || !token.length) {
return
}

Expand All @@ -119,11 +119,11 @@ export default class Oauth2Scheme {

// Append token_type
if (this.options.token_type) {
accessToken = this.options.token_type + ' ' + accessToken
token = this.options.token_type + ' ' + token
}

// Store token
this.$auth.setToken(this.name, accessToken)
this.$auth.setToken(this.name, token)

// Redirect to home
this.$auth.redirect('home', true)
Expand Down

0 comments on commit 554a042

Please sign in to comment.