Merge pull request #7705 from rosieks/master

oidc-token-manager definition
This commit is contained in:
Horiuchi_H
2016-01-21 11:16:31 +09:00
2 changed files with 167 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);
+120
View File
@@ -0,0 +1,120 @@
// 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: string, config: any): DefaultPromise;
}
class DefaultPromise {
constructor(promise: any);
then(successCallback: (value?: any) => void, errorCallback: (reason?: any) => void): DefaultPromise;
catch(errorCallback: () => void): DefaultPromise;
}
class DefaultPromiseFactory {
resolve(value: any): DefaultPromise;
reject(reason: any): DefaultPromise;
create(callback: any): DefaultPromise;
}
interface OidcClientSettings {
request_state_key?: string;
request_state_store?: any;
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): DefaultPromise;
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?: any;
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: DefaultHttpRequest): void;
}
interface OidcToken {
profile: string;
id_token: string;
access_token: string;
expires_at: number;
scope: string;
scopes: string[];
session_state: any;
expired: boolean;
expires_in: number;
toJSON(): string;
}
interface OidcTokenManager {
profile: any;
id_token: string;
access_token: string;
expired: boolean;
expires_in: number;
expires_at: number;
scope: string;
scopes: string[];
session_state: any;
saveToken(token: OidcToken): 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;