diff --git a/packages/okta-vue/README.md b/packages/okta-vue/README.md index a8cd75073..aac8c72fe 100644 --- a/packages/okta-vue/README.md +++ b/packages/okta-vue/README.md @@ -225,12 +225,14 @@ router.beforeEach((from, to, next) { - `scope` *(optional)*: Reserved or custom claims to be returned in the tokens - `response_type` *(optional)*: Desired token grant types -#### `$auth.loginRedirect` +#### `$auth.loginRedirect(fromUri, additionalParams)` -Performs a full page redirect to Okta based on the initial configuration. If you have an Okta `sessionToken`, you can bypass the full-page redirect by passing in this token. This is recommended when using the [Okta Sign-In Widget](https://github.com/okta/okta-signin-widget). Simply pass in a `sessionToken` into the `loginRedirect` method follows: +Performs a full page redirect to Okta based on the initial configuration. This method accepts a `fromUri` parameter to push the user to after successful authentication. + +The parameter `additionalParams` is mapped to the [AuthJS OpenID Connect Options](https://github.com/okta/okta-auth-js#openid-connect-options). This will override any existing [configuration](#configuration). As an example, if you have an Okta `sessionToken`, you can bypass the full-page redirect by passing in this token. This is recommended when using the [Okta Sign-In Widget](https://github.com/okta/okta-signin-widget). Simply pass in a `sessionToken` into the `loginRedirect` method follows: ```typescript -this.$auth.loginRedirect({ +this.$auth.loginRedirect('/profile', { sessionToken: /* sessionToken */ }) ``` diff --git a/packages/okta-vue/package.json b/packages/okta-vue/package.json index 647bd468f..e8bea858e 100644 --- a/packages/okta-vue/package.json +++ b/packages/okta-vue/package.json @@ -9,7 +9,7 @@ ], "scripts": { "prebuild": "npm run build:package-info", - "prestart": "npm run build", + "prestart": "npm run build && npm run build:harness", "pretest": "npm run build && npm run build:harness", "prepublish": "npm run build", "jest": "jest src/", diff --git a/packages/okta-vue/src/Auth.js b/packages/okta-vue/src/Auth.js index 7dc5082b1..485fbbba7 100644 --- a/packages/okta-vue/src/Auth.js +++ b/packages/okta-vue/src/Auth.js @@ -13,7 +13,10 @@ function install (Vue, options) { oktaAuth.userAgent = `${packageInfo.name}/${packageInfo.version} ${oktaAuth.userAgent}` Vue.prototype.$auth = { - loginRedirect (additionalParams) { + loginRedirect (fromUri, additionalParams) { + if (fromUri) { + localStorage.setItem('referrerPath', fromUri) + } return oktaAuth.token.getWithRedirect({ responseType: authConfig.response_type, scopes: authConfig.scope.split(' '), @@ -63,8 +66,7 @@ function install (Vue, options) { authRedirectGuard () { return async (to, from, next) => { if (to.matched.some(record => record.meta.requiresAuth) && !(await this.isAuthenticated())) { - localStorage.setItem('referrerPath', to.path || '/') - this.loginRedirect() + this.loginRedirect(to.path) } else { next() } diff --git a/packages/okta-vue/test/e2e/harness/src/App.vue b/packages/okta-vue/test/e2e/harness/src/App.vue index 9a40f986a..891131db7 100644 --- a/packages/okta-vue/test/e2e/harness/src/App.vue +++ b/packages/okta-vue/test/e2e/harness/src/App.vue @@ -2,7 +2,7 @@