From 27f3db2d27e1a1e95784cffa1438b8557d4e7a17 Mon Sep 17 00:00:00 2001 From: Michael Dodge Date: Tue, 24 Apr 2018 12:10:34 -0600 Subject: [PATCH 1/3] Add definitions for okta-vue --- types/okta__okta-vue/index.d.ts | 36 ++++++++++++++ types/okta__okta-vue/okta__okta-vue-tests.ts | 50 ++++++++++++++++++++ types/okta__okta-vue/package.json | 7 +++ types/okta__okta-vue/tsconfig.json | 23 +++++++++ types/okta__okta-vue/tslint.json | 1 + 5 files changed, 117 insertions(+) create mode 100644 types/okta__okta-vue/index.d.ts create mode 100644 types/okta__okta-vue/okta__okta-vue-tests.ts create mode 100644 types/okta__okta-vue/package.json create mode 100644 types/okta__okta-vue/tsconfig.json create mode 100644 types/okta__okta-vue/tslint.json diff --git a/types/okta__okta-vue/index.d.ts b/types/okta__okta-vue/index.d.ts new file mode 100644 index 0000000000..75a3332c68 --- /dev/null +++ b/types/okta__okta-vue/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for okta-vue 1.0 +// Project: https://github.com/okta/okta-oidc-js/tree/master/packages/okta-vue +// Definitions by: Mike Dodge +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { VueConstructor, PluginFunction } from 'vue'; +import { NavigationGuard } from 'vue-router'; + +export interface OktaVueOptions { + issuer: string; + client_id: string; + redirect_uri: string; + scope: string; +} +export function OktaVuePlugin(vm: VueConstructor, options: OktaVueOptions): void; +export namespace OktaVuePlugin { + function handleCallback(): VueConstructor; +} +export default OktaVuePlugin; + +declare module 'vue/types/vue' { + interface Vue { + $auth: { + loginRedirect(): void; + logout(): Promise; + isAuthenticated(): Promise; + handleAuthentication(): Promise; + getFromUri(): string; + getIdToken(): Promise; + getAccessToken(): Promise; + getUser(): Promise; + authRedirectGuardd(): Promise; + }; + } +} diff --git a/types/okta__okta-vue/okta__okta-vue-tests.ts b/types/okta__okta-vue/okta__okta-vue-tests.ts new file mode 100644 index 0000000000..881726a9f0 --- /dev/null +++ b/types/okta__okta-vue/okta__okta-vue-tests.ts @@ -0,0 +1,50 @@ +import Vue from 'vue'; +import Router from 'vue-router'; +import Auth from 'okta__okta-vue'; + +Vue.use(Auth, { + issuer: 'https://{yourOktaDomain}.com/oauth2/default', + client_id: '{client_id}', + redirect_uri: 'http://localhost:{port}/implicit/callback', + scope: 'openid profile email' +}); + +Vue.use(Router); +const router = new Router({ + mode: 'history', + routes: [ + { path: '/implicit/callback', component: Auth.handleCallback() }, + { + path: '/protected', + component: { + name: 'protected', + template: '
Protected Route
' + }, + meta: { + requiresAuth: true + } + }, + ] +}); + +const redirectGuard = Vue.prototype.$auth.authRedirectGuard(); +router.beforeEach(redirectGuard); + +const component = Vue.extend({ + mounted() { + const authd = this.$auth.isAuthenticated(); + const userInfo = this.$auth.getUser(); + const handleAuth = this.$auth.handleAuthentication(); + const path = this.$auth.getFromUri(); + const idToken = this.$auth.getIdToken(); + const accessToken = this.$auth.getAccessToken(); + }, + methods: { + logout() { + const logoutPromise = this.$auth.logout(); + }, + redirect() { + this.$auth.loginRedirect(); + }, + }, +}); diff --git a/types/okta__okta-vue/package.json b/types/okta__okta-vue/package.json new file mode 100644 index 0000000000..fe98511c31 --- /dev/null +++ b/types/okta__okta-vue/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "dependencies": { + "vue": "^2.5.9", + "vue-router": "^3.0.1" + } +} diff --git a/types/okta__okta-vue/tsconfig.json b/types/okta__okta-vue/tsconfig.json new file mode 100644 index 0000000000..f114dc0fe8 --- /dev/null +++ b/types/okta__okta-vue/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "okta__okta-vue-tests.ts" + ] +} diff --git a/types/okta__okta-vue/tslint.json b/types/okta__okta-vue/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/okta__okta-vue/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From cba41f0aca7c25c228af64d33a1850be413b8118 Mon Sep 17 00:00:00 2001 From: Michael Dodge Date: Mon, 21 May 2018 13:44:19 -0600 Subject: [PATCH 2/3] Update to include install function --- types/okta__okta-vue/index.d.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/types/okta__okta-vue/index.d.ts b/types/okta__okta-vue/index.d.ts index 75a3332c68..5f67b78fc2 100644 --- a/types/okta__okta-vue/index.d.ts +++ b/types/okta__okta-vue/index.d.ts @@ -7,16 +7,18 @@ import { VueConstructor, PluginFunction } from 'vue'; import { NavigationGuard } from 'vue-router'; -export interface OktaVueOptions { - issuer: string; - client_id: string; - redirect_uri: string; - scope: string; -} -export function OktaVuePlugin(vm: VueConstructor, options: OktaVueOptions): void; -export namespace OktaVuePlugin { +declare namespace OktaVuePlugin { + interface OktaVueOptions { + issuer: string; + client_id: string; + redirect_uri: string; + scope: string; + } + + function install(vm: VueConstructor, options: OktaVueOptions): PluginFunction; function handleCallback(): VueConstructor; } +declare function OktaVuePlugin(): PluginFunction; export default OktaVuePlugin; declare module 'vue/types/vue' { From 9bb15a49700d315490fae7beb18317bf6b999186 Mon Sep 17 00:00:00 2001 From: Michael Dodge Date: Wed, 30 May 2018 16:52:34 -0600 Subject: [PATCH 3/3] Update okta-vue defs with new loginRedirect args --- types/okta__okta-vue/index.d.ts | 14 ++++++++++++-- types/okta__okta-vue/okta__okta-vue-tests.ts | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/types/okta__okta-vue/index.d.ts b/types/okta__okta-vue/index.d.ts index 5f67b78fc2..da7ec34d2e 100644 --- a/types/okta__okta-vue/index.d.ts +++ b/types/okta__okta-vue/index.d.ts @@ -12,9 +12,19 @@ declare namespace OktaVuePlugin { issuer: string; client_id: string; redirect_uri: string; - scope: string; + scope?: string; + response_type?: string; } + interface OktaOpenIDOptions { + sessionToken?: string; + responseMode?: string; + responseType?: string | string[]; + scopes?: string[]; + state?: string; + nonce?: string; + } + function install(vm: VueConstructor, options: OktaVueOptions): PluginFunction; function handleCallback(): VueConstructor; } @@ -24,7 +34,7 @@ export default OktaVuePlugin; declare module 'vue/types/vue' { interface Vue { $auth: { - loginRedirect(): void; + loginRedirect(fromUri?: string, additionalParams?: OktaVuePlugin.OktaOpenIDOptions): void; logout(): Promise; isAuthenticated(): Promise; handleAuthentication(): Promise; diff --git a/types/okta__okta-vue/okta__okta-vue-tests.ts b/types/okta__okta-vue/okta__okta-vue-tests.ts index 881726a9f0..70ec9135f4 100644 --- a/types/okta__okta-vue/okta__okta-vue-tests.ts +++ b/types/okta__okta-vue/okta__okta-vue-tests.ts @@ -46,5 +46,15 @@ const component = Vue.extend({ redirect() { this.$auth.loginRedirect(); }, + profileRedirect() { + this.$auth.loginRedirect('/profile', { + sessionToken: 'string', + responseMode: 'string', + responseType: 'string', + scopes: ['string1', 'string2'], + state: 'string', + nonce: 'string', + }); + }, }, });