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 @@
Home - + Protected
@@ -24,6 +24,9 @@ export default { async isAuthenticated () { this.authenticated = await this.$auth.isAuthenticated() }, + login () { + this.$auth.loginRedirect('/') + }, async logout () { await this.$auth.logout() await this.isAuthenticated() diff --git a/packages/okta-vue/test/e2e/harness/src/components/SessionTokenLogin.vue b/packages/okta-vue/test/e2e/harness/src/components/SessionTokenLogin.vue index 9efa6866b..5130e4f66 100644 --- a/packages/okta-vue/test/e2e/harness/src/components/SessionTokenLogin.vue +++ b/packages/okta-vue/test/e2e/harness/src/components/SessionTokenLogin.vue @@ -28,7 +28,7 @@ export default { password: this.password }) .then(res => - this.$auth.loginRedirect({ + this.$auth.loginRedirect('/protected', { sessionToken: res.sessionToken }) ) diff --git a/packages/okta-vue/test/e2e/harness/test/e2e/specs/test.js b/packages/okta-vue/test/e2e/harness/test/e2e/specs/test.js index e4524ba9d..71b8ada74 100644 --- a/packages/okta-vue/test/e2e/harness/test/e2e/specs/test.js +++ b/packages/okta-vue/test/e2e/harness/test/e2e/specs/test.js @@ -17,6 +17,7 @@ module.exports = { .setValue('#okta-signin-password', process.env.PASSWORD) .click('#okta-signin-submit') .waitForElementVisible('#app', 5000) + .assert.urlContains('/protected') .assert.elementPresent('#logout-button') .assert.containsText('.protected', 'Protected!') .pause(2000) // Wait for async function to finish @@ -52,6 +53,7 @@ module.exports = { .setValue('#password', process.env.PASSWORD) .click('#submit') .waitForElementVisible('#logout-button', 5000) + .assert.urlContains('/protected') .assert.elementPresent('#logout-button') .click('#logout-button') .end()