Skip to content

Commit

Permalink
feat: generate nounce for id_token response type (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Fernando Alvarez Franco authored and pi0 committed May 23, 2019
1 parent 39fa137 commit b730203
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/schemes/oauth2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { encodeQuery, parseQuery, randomString } from '../utilities'
import nanoid from 'nanoid'

const DEFAULTS = {
token_type: 'Bearer',
Expand Down Expand Up @@ -80,6 +81,15 @@ export default class Oauth2Scheme {
opts.audience = this.options.audience
}

// Set Nonce Value if response_type contains id_token to mitigate Replay Attacks
// More Info: https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes
// More Info: https://tools.ietf.org/html/draft-ietf-oauth-v2-threatmodel-06#section-4.6.2
if (opts.response_type.includes('id_token')) {
// nanoid auto-generates an URL Friendly, unique Cryptographic string
// Recommended by Auth0 on https://auth0.com/docs/api-auth/tutorials/nonce
opts.nonce = nanoid()
}

this.$auth.$storage.setLocalStorage(this.name + '.state', opts.state)

const url = this.options.authorization_endpoint + '?' + encodeQuery(opts)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"cookie": "^0.3.1",
"dotprop": "^1.0.2",
"js-cookie": "^2.2.0",
"lodash": "^4.17.11"
"lodash": "^4.17.11",
"nanoid": "^2.0.1"
},
"devDependencies": {
"@nuxtjs/toast": "^3.0.2",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6425,6 +6425,11 @@ nan@^2.9.2:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==

nanoid@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.1.tgz#deb55cac196e3f138071911dabbc3726eb048864"
integrity sha512-k1u2uemjIGsn25zmujKnotgniC/gxQ9sdegdezeDiKdkDW56THUMqlz3urndKCXJxA6yPzSZbXx/QCMe/pxqsA==

nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down

0 comments on commit b730203

Please sign in to comment.