Add definitions for okta-vue

This commit is contained in:
Michael Dodge
2018-04-24 12:10:34 -06:00
parent ee2f1b215e
commit 27f3db2d27
5 changed files with 117 additions and 0 deletions
+36
View File
@@ -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 <https://github.com/innovation-team>
// 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<void>;
isAuthenticated(): Promise<boolean>;
handleAuthentication(): Promise<void>;
getFromUri(): string;
getIdToken(): Promise<string>;
getAccessToken(): Promise<string>;
getUser(): Promise<any>;
authRedirectGuardd(): Promise<NavigationGuard>;
};
}
}
@@ -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: '<div>Protected Route</div>'
},
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();
},
},
});
+7
View File
@@ -0,0 +1,7 @@
{
"private": true,
"dependencies": {
"vue": "^2.5.9",
"vue-router": "^3.0.1"
}
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }