From 27f3db2d27e1a1e95784cffa1438b8557d4e7a17 Mon Sep 17 00:00:00 2001 From: Michael Dodge Date: Tue, 24 Apr 2018 12:10:34 -0600 Subject: [PATCH] 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" }