Initial version of oidc-token-manager definition

This commit is contained in:
Rosiek.Slawomir YSI
2016-01-20 15:21:43 +01:00
parent 6035d7e34a
commit fc78e56910
2 changed files with 154 additions and 0 deletions
@@ -0,0 +1,47 @@
/// <reference path="oidc-token-manager.d.ts" />
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);
+107
View File
@@ -0,0 +1,107 @@
// Type definitions for oidc-token-manager
// Project: https://github.com/IdentityModel/oidc-token-manager
// Definitions by: Sławomir Rosiek <https://github.com/rosieks>
// 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;