Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use IdToken instead of AccessToken #121

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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