From fc78e5691045ff3cb9eed72e32bb86719f5ac61b Mon Sep 17 00:00:00 2001 From: "Rosiek.Slawomir YSI" Date: Wed, 20 Jan 2016 15:21:43 +0100 Subject: [PATCH] Initial version of oidc-token-manager definition --- .../oidc-token-manager-tests.ts | 47 ++++++++ oidc-token-manager/oidc-token-manager.d.ts | 107 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 oidc-token-manager/oidc-token-manager-tests.ts create mode 100644 oidc-token-manager/oidc-token-manager.d.ts diff --git a/oidc-token-manager/oidc-token-manager-tests.ts b/oidc-token-manager/oidc-token-manager-tests.ts new file mode 100644 index 000000000..71261cce1 --- /dev/null +++ b/oidc-token-manager/oidc-token-manager-tests.ts @@ -0,0 +1,47 @@ +/// + +var config = { + client_id: "implicitclient", + redirect_uri: window.location.protocol + "//" + window.location.host + "/callback.html", + post_logout_redirect_uri: window.location.protocol + "//" + window.location.host + "/index.html", + response_type: "id_token token", + scope: "openid profile email read write", + authority: "https://localhost:44333/core", + silent_redirect_uri: window.location.protocol + "//" + window.location.host + "/frame.html", + popup_redirect_uri: window.location.protocol + "//" + window.location.host + "/popup.html", + silent_renew: true +}; +var mgr = new OidcTokenManager(config); +if (!mgr.expired) { + console.log("Token loaded, expires in: ", mgr.expires_in); + console.log("profile", mgr.profile); + console.log("access_token", !!mgr.access_token); +} +else { + console.log("No token loaded"); +} +mgr.addOnTokenObtained(function () { + console.log("token obtained, scopes: ", mgr.scopes); +}); +mgr.addOnTokenRemoved(function () { + console.log("token removed"); +}); +mgr.addOnTokenExpiring(function () { + console.log("token is about to expire"); + //mgr.renewTokenSilent(); +}); +mgr.addOnTokenExpired(function () { + console.log("token expired"); +}); + mgr.redirectForToken(); + mgr.openPopupForTokenAsync().then(function () { + console.log('popup success'); + }, function (err) { + console.log('popup error: ', err); + }); + mgr.removeToken(); + mgr.redirectForLogout(); +function toggleForget() { +} +mgr.addOnTokenObtained(toggleForget); +mgr.addOnTokenRemoved(toggleForget); \ No newline at end of file diff --git a/oidc-token-manager/oidc-token-manager.d.ts b/oidc-token-manager/oidc-token-manager.d.ts new file mode 100644 index 000000000..ce01f457b --- /dev/null +++ b/oidc-token-manager/oidc-token-manager.d.ts @@ -0,0 +1,107 @@ +// Type definitions for oidc-token-manager +// Project: https://github.com/IdentityModel/oidc-token-manager +// Definitions by: Sławomir Rosiek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module Oidc { + class DefaultHttpRequest { + getJSON(url, config); + } + + class DefaultPromise { + constructor(promise); + then(successCallback, errorCallback): DefaultPromise; + catch(errorCallback): DefaultPromise; + } + + class DefaultPromiseFactory { + resolve(value): DefaultPromise; + reject(reason): DefaultPromise; + create(callback): DefaultPromise; + } + + interface OidcClientSettings { + request_state_key?: string; + request_state_store?; + load_user_profile?: boolean; + filter_protocol_claims?: boolean; + authority?: string; + response_type?: string; + } + + interface OidcClient_Static { + new (settings: OidcClientSettings): OidcTokenManager; + } + + interface OidcClient { + isOidc: boolean; + isOAuth: boolean; + + loadMetadataAsync(): DefaultPromise; + loadX509SigningKeyAsync(): DefaultPromise; + loadUserProfile(access_token: string); + loadAuthorizationEndpoint(): void; + createTokenRequestAsync(): DefaultPromise; + createLogoutRequestAsync(id_token_hint: string): DefaultPromise; + validateIdTokenAsync(id_token: string, nonce: string, access_token: string): DefaultPromise; + validateAccessTokenAsync(id_token_contents: string, access_token: string): DefaultPromise; + validateIdTokenAndAccessTokenAsync(id_token: string, nonce: string, access_token: string): DefaultPromise; + processResponseAsync(queryString: string): DefaultPromise; + } + + interface OidcTokenManagerSettings { + persist?: boolean; + store?; + persistKey?: string; + client_id?: string; + redirect_uri?: string; + post_logout_redirect_uri?: string; + response_type?: string; + scope?: string; + authority?: string; + popup_redirect_uri?: string; + silent_redirect_uri?: string; + silent_renew?: boolean; + } + + interface PopupSettings { + features?: string; + target?: string; + } + + interface OidcTokenManager_Static { + new (settings?: OidcTokenManagerSettings): OidcTokenManager; + setPromiseFactory(promiseFactory: DefaultPromiseFactory): void; + setHttpRequest(httpRequest): void; + } + + interface OidcTokenManager { + profile; + id_token: string; + access_token: string; + expired: boolean; + expires_in: number; + expires_at: number; + scope; + scopes: any[]; + session_state; + + saveToken(token): void; + addOnTokenRemoved(cb: () => void): void; + addOnTokenObtained(cb: () => void): void; + addOnTokenExpiring(cb: () => void): void; + addOnTokenExpired(cb: () => void): void; + addOnSilentTokenRenewFailed(cb: () => void): void; + removeToken(): void; + redirectForToken(): void; + redirectForLogout(): void; + processTokenCallbackAsync(queryString?: string): DefaultPromise; + renewTokenSilentAsync(): DefaultPromise; + processTokenCallbackSilent(hash?: string): void; + openPopupForTokenAsync(popupSettings?: PopupSettings): DefaultPromise; + processTokenPopup(hash?: string): void; + } +} + +declare var OidcTokenManager: Oidc.OidcTokenManager_Static; +declare var OidcClient: Oidc.OidcClient_Static; \ No newline at end of file