From 8f7a306a4875d0fb1124e67a84c7ab3eea3f8d09 Mon Sep 17 00:00:00 2001 From: Reto Rezzonico Date: Wed, 27 May 2015 16:28:51 +0200 Subject: [PATCH] Add definitions for angular-jwt --- angular-jwt/angular-jwt-tests.ts | 17 +++++++++++++++++ angular-jwt/angular-jwt.d.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 angular-jwt/angular-jwt-tests.ts create mode 100644 angular-jwt/angular-jwt.d.ts diff --git a/angular-jwt/angular-jwt-tests.ts b/angular-jwt/angular-jwt-tests.ts new file mode 100644 index 0000000000..2e7ccbc08d --- /dev/null +++ b/angular-jwt/angular-jwt-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +var app = angular.module("angular-jwt-tests", ["angular-jwt"]); + +var $jwtHelper: angular.jwt.IJwtHelper; + +var expToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3NhbXBsZXMuYXV0aDAuY29tLyIsInN1YiI6ImZhY2Vib29rfDEwMTU0Mjg3MDI3NTEwMzAyIiwiYXVkIjoiQlVJSlNXOXg2MHNJSEJ3OEtkOUVtQ2JqOGVESUZ4REMiLCJleHAiOjE0MTIyMzQ3MzAsImlhdCI6MTQxMjE5ODczMH0.7M5sAV50fF1-_h9qVbdSgqAnXVF7mz3I6RjS6JiH0H8'; +var tokenPayload = $jwtHelper.decodeToken(expToken); +var date = $jwtHelper.getTokenExpirationDate(expToken); +var bool = $jwtHelper.isTokenExpired(expToken); + +var $jwtInterceptor: angular.jwt.IJwtInterceptor; + +$jwtInterceptor.tokenGetter = () => { + return expToken; +} \ No newline at end of file diff --git a/angular-jwt/angular-jwt.d.ts b/angular-jwt/angular-jwt.d.ts new file mode 100644 index 0000000000..ec0e03e16c --- /dev/null +++ b/angular-jwt/angular-jwt.d.ts @@ -0,0 +1,30 @@ +// Type definitions for angular-jwt 0.0.8 +// Project: https://github.com/auth0/angular-jwt +// Definitions by: Reto Rezzonico +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module angular.jwt { + + interface JwtToken { + iss: string; + sub: string; + aud: string; + exp: number; + nbf: number; + iat: number; + jti: string; + unique_name: string; + } + + interface IJwtHelper { + decodeToken(token: string): JwtToken; + getTokenExpirationDate(token: any): Date; + isTokenExpired(token: any, offsetSeconds?: number): boolean; + } + + interface IJwtInterceptor { + tokenGetter(): string; + } +} \ No newline at end of file