Skip to content

Commit 554a042

Browse files
sschadwickpi0
authored andcommitted
feat(scheme/oauth2): add option to use IdToken instead of AccessToken (#121)
1 parent 08299ea commit 554a042

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/schemes/oauth2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ auth: {
1818
token_type: 'Bearer',
1919
redirect_uri: undefined,
2020
client_id: 'SET_ME',
21+
token_key: 'access_token'
2122
}
2223
}
2324
}
@@ -55,6 +56,10 @@ Should be same as login page or relative path to welcome screen. ([example](http
5556

5657
**REQUIRED** - oauth2 client id.
5758

59+
### `token_key`
60+
61+
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'`.
62+
5863
## Usage
5964

6065
```js

lib/schemes/oauth2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export default class Oauth2Scheme {
8888
const search = parseQuery(window.location.search.substr(1))
8989
const parsedQuery = Object.assign({}, search, hash)
9090

91-
// accessToken
92-
let accessToken = parsedQuery.access_token
91+
// accessToken/idToken
92+
let token = parsedQuery[this.options.token_key || 'access_token']
9393

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

104104
if (data.access_token) {
105-
accessToken = data.access_token
105+
token = data.access_token
106106
}
107107
}
108108

109-
if (!accessToken || !accessToken.length) {
109+
if (!token || !token.length) {
110110
return
111111
}
112112

@@ -119,11 +119,11 @@ export default class Oauth2Scheme {
119119

120120
// Append token_type
121121
if (this.options.token_type) {
122-
accessToken = this.options.token_type + ' ' + accessToken
122+
token = this.options.token_type + ' ' + token
123123
}
124124

125125
// Store token
126-
this.$auth.setToken(this.name, accessToken)
126+
this.$auth.setToken(this.name, token)
127127

128128
// Redirect to home
129129
this.$auth.redirect('home', true)

0 commit comments

Comments
 (0)