From 0d60c2d90eff9ed9001f7ef9d09cc37b70b856c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Thu, 23 May 2019 20:42:03 +0200 Subject: [PATCH] feat(oauth2): support passing extra query params (#358) --- docs/schemes/oauth2.md | 10 +++++++++- lib/schemes/oauth2.js | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/schemes/oauth2.md b/docs/schemes/oauth2.md index 1ab274da2..49b00fe1c 100644 --- a/docs/schemes/oauth2.md +++ b/docs/schemes/oauth2.md @@ -26,9 +26,17 @@ auth: { ``` ```js -this.$auth.loginWith('social') +this.$auth.loginWith('social', options) ``` +`options` is an optional object with `params` property defining additional URL parameters to pass to authorization endpoint. For example: + +```js +this.$auth.loginWith('social', { params: { lang: 'en' } }) +``` + +will add extra query parameter `&lang=en` to a URL. + ### `authorization_endpoint` **REQUIRED** - Endpoint to start login flow. Depends on oauth service. diff --git a/lib/schemes/oauth2.js b/lib/schemes/oauth2.js index 8082e0786..8fded3844 100644 --- a/lib/schemes/oauth2.js +++ b/lib/schemes/oauth2.js @@ -63,7 +63,7 @@ export default class Oauth2Scheme { return this.$auth.reset() } - login () { + login ({ params } = {}) { const opts = { protocol: 'oauth2', response_type: this.options.response_type, @@ -73,6 +73,7 @@ export default class Oauth2Scheme { // Note: The primary reason for using the state parameter is to mitigate CSRF attacks. // @see: https://auth0.com/docs/protocols/oauth2/oauth-state state: this.options.state || randomString(), + ...params, }; if (this.options.audience) {