-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:wi3land/ionic-appauth
- Loading branch information
Showing
46 changed files
with
1,488 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.idea | ||
node_modules | ||
/lib | ||
*.tgz | ||
|
||
# ignore generated directories in demos | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TokenResponse } from '@openid/appauth'; | ||
export declare enum AuthActions { | ||
Init = "Init", | ||
SignInSuccess = "Sign In Success", | ||
SignInFailed = "Sign In Failed", | ||
SignOutSuccess = "Sign Out Success", | ||
SignOutFailed = "Sign Out Failed", | ||
RefreshSuccess = "Refresh Success", | ||
RefreshFailed = "Refesh Failed", | ||
LoadTokenFromStorageSuccess = "Get Token From Storage Success", | ||
LoadTokenFromStorageFailed = "Get Token From Storage Failed", | ||
LoadUserInfoSuccess = "Load User Info Success", | ||
LoadUserInfoFailed = "Load User Info Failed", | ||
RevokeTokensSuccess = "Revoke Tokens Success", | ||
RevokeTokensFailed = "Revoke Tokens Failed" | ||
} | ||
export interface IAuthAction { | ||
action: string; | ||
tokenResponse?: TokenResponse; | ||
error?: string; | ||
user?: any; | ||
} | ||
export declare class AuthActionBuilder { | ||
static Init(): IAuthAction; | ||
static SignOutSuccess(): IAuthAction; | ||
static SignOutFailed(error: any): IAuthAction; | ||
static RefreshSuccess(tokenResponse: TokenResponse): IAuthAction; | ||
static RefreshFailed(error: any): IAuthAction; | ||
static SignInSuccess(tokenResponse: TokenResponse): IAuthAction; | ||
static SignInFailed(error: any): IAuthAction; | ||
static LoadTokenFromStorageSuccess(tokenResponse: TokenResponse): IAuthAction; | ||
static LoadTokenFromStorageFailed(error: any): IAuthAction; | ||
static RevokeTokensSuccess(): IAuthAction; | ||
static RevokeTokensFailed(error: any): IAuthAction; | ||
static LoadUserInfoSuccess(user: any): IAuthAction; | ||
static LoadUserInfoFailed(error: any): IAuthAction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
export var AuthActions; | ||
(function (AuthActions) { | ||
AuthActions["Init"] = "Init"; | ||
AuthActions["SignInSuccess"] = "Sign In Success"; | ||
AuthActions["SignInFailed"] = "Sign In Failed"; | ||
AuthActions["SignOutSuccess"] = "Sign Out Success"; | ||
AuthActions["SignOutFailed"] = "Sign Out Failed"; | ||
AuthActions["RefreshSuccess"] = "Refresh Success"; | ||
AuthActions["RefreshFailed"] = "Refesh Failed"; | ||
AuthActions["LoadTokenFromStorageSuccess"] = "Get Token From Storage Success"; | ||
AuthActions["LoadTokenFromStorageFailed"] = "Get Token From Storage Failed"; | ||
AuthActions["LoadUserInfoSuccess"] = "Load User Info Success"; | ||
AuthActions["LoadUserInfoFailed"] = "Load User Info Failed"; | ||
AuthActions["RevokeTokensSuccess"] = "Revoke Tokens Success"; | ||
AuthActions["RevokeTokensFailed"] = "Revoke Tokens Failed"; | ||
})(AuthActions || (AuthActions = {})); | ||
export class AuthActionBuilder { | ||
static Init() { | ||
return { | ||
action: AuthActions.Init, | ||
}; | ||
} | ||
static SignOutSuccess() { | ||
return { | ||
action: AuthActions.SignOutSuccess, | ||
}; | ||
} | ||
static SignOutFailed(error) { | ||
return { | ||
action: AuthActions.SignOutFailed, | ||
error: error.message | ||
}; | ||
} | ||
static RefreshSuccess(tokenResponse) { | ||
return { | ||
action: AuthActions.RefreshSuccess, | ||
tokenResponse | ||
}; | ||
} | ||
static RefreshFailed(error) { | ||
return { | ||
action: AuthActions.RefreshFailed, | ||
error: error.message, | ||
}; | ||
} | ||
static SignInSuccess(tokenResponse) { | ||
return { | ||
action: AuthActions.SignInSuccess, | ||
tokenResponse | ||
}; | ||
} | ||
static SignInFailed(error) { | ||
return { | ||
action: AuthActions.SignInFailed, | ||
error: error.message | ||
}; | ||
} | ||
static LoadTokenFromStorageSuccess(tokenResponse) { | ||
return { | ||
action: AuthActions.LoadTokenFromStorageSuccess, | ||
tokenResponse | ||
}; | ||
} | ||
static LoadTokenFromStorageFailed(error) { | ||
return { | ||
action: AuthActions.LoadTokenFromStorageFailed, | ||
error: error.message | ||
}; | ||
} | ||
static RevokeTokensSuccess() { | ||
return { | ||
action: AuthActions.RevokeTokensSuccess, | ||
tokenResponse: undefined | ||
}; | ||
} | ||
static RevokeTokensFailed(error) { | ||
return { | ||
action: AuthActions.RevokeTokensFailed, | ||
error: error.message | ||
}; | ||
} | ||
static LoadUserInfoSuccess(user) { | ||
return { | ||
action: AuthActions.LoadUserInfoSuccess, | ||
user | ||
}; | ||
} | ||
static LoadUserInfoFailed(error) { | ||
return { | ||
action: AuthActions.LoadUserInfoFailed, | ||
error: error.message | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export declare abstract class Browser { | ||
protected onCloseFunction: Function; | ||
abstract showWindow(url: string, callbackUrl?: string): string | undefined | Promise<string | undefined>; | ||
abstract closeWindow(): void | Promise<void>; | ||
browserCloseListener(closeBrowserEvent: Function): void; | ||
} | ||
export declare class DefaultBrowser extends Browser { | ||
showWindow(url: string): string | undefined; | ||
closeWindow(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export class Browser { | ||
constructor() { | ||
this.onCloseFunction = () => { }; | ||
} | ||
browserCloseListener(closeBrowserEvent) { | ||
this.onCloseFunction = closeBrowserEvent; | ||
} | ||
} | ||
export class DefaultBrowser extends Browser { | ||
showWindow(url) { | ||
const openWindow = window.open(url, "_self"); | ||
if (openWindow) { | ||
openWindow.addEventListener('beforeupload', () => this.onCloseFunction()); | ||
} | ||
return; | ||
} | ||
closeWindow() { | ||
// Invoking window.close() is not desired. It will either be ignored (most of the time), | ||
// or it will close the current browser tab if this site was opened via a "_blank" target. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export declare enum AuthenticationType { | ||
Token = "token", | ||
AuthorizationCode = "code", | ||
IdToken = "id_token" | ||
} | ||
export interface IAuthConfig { | ||
client_id: string; | ||
client_secret?: string; | ||
server_host: string; | ||
redirect_url: string; | ||
end_session_redirect_url: string; | ||
scopes: string; | ||
pkce: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export var AuthenticationType; | ||
(function (AuthenticationType) { | ||
AuthenticationType["Token"] = "token"; | ||
AuthenticationType["AuthorizationCode"] = "code"; | ||
AuthenticationType["IdToken"] = "id_token"; | ||
})(AuthenticationType || (AuthenticationType = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { IAuthAction } from './auth-action'; | ||
import { TokenResponse } from '@openid/appauth'; | ||
import { Guid } from "guid-typescript"; | ||
import { IAuthSession } from './auth-session'; | ||
export declare abstract class BaseAuthObserver { | ||
protected id: Guid; | ||
abstract update(action: IAuthAction): void; | ||
} | ||
export declare class AuthObserver extends BaseAuthObserver { | ||
private func; | ||
constructor(func: (action: IAuthAction) => void); | ||
update(action: IAuthAction): void; | ||
static Create(func: (action: IAuthAction) => void): AuthObserver; | ||
} | ||
export declare class TokenObserver extends BaseAuthObserver { | ||
token?: TokenResponse; | ||
update(action: IAuthAction): void; | ||
} | ||
export declare class ActionHistoryObserver extends BaseAuthObserver { | ||
history: IAuthAction[]; | ||
lastAction?: IAuthAction; | ||
update(action: IAuthAction): void; | ||
clear(): void; | ||
} | ||
export declare class SessionObserver extends BaseAuthObserver { | ||
session: IAuthSession; | ||
update(action: IAuthAction): void; | ||
} | ||
export declare class ConsoleLogObserver extends BaseAuthObserver { | ||
update(action: IAuthAction): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { AuthActions } from './auth-action'; | ||
import { Guid } from "guid-typescript"; | ||
import { DefaultAuthSession } from './auth-session'; | ||
export class BaseAuthObserver { | ||
constructor() { | ||
this.id = Guid.create(); | ||
} | ||
} | ||
export class AuthObserver extends BaseAuthObserver { | ||
constructor(func) { | ||
super(); | ||
this.func = func; | ||
} | ||
update(action) { | ||
this.func(action); | ||
} | ||
static Create(func) { | ||
return new AuthObserver(func); | ||
} | ||
} | ||
export class TokenObserver extends BaseAuthObserver { | ||
update(action) { | ||
this.token = action.tokenResponse; | ||
} | ||
} | ||
export class ActionHistoryObserver extends BaseAuthObserver { | ||
constructor() { | ||
super(...arguments); | ||
this.history = []; | ||
} | ||
update(action) { | ||
this.lastAction = action; | ||
this.history.push(action); | ||
} | ||
clear() { | ||
this.history = []; | ||
this.lastAction = undefined; | ||
} | ||
} | ||
export class SessionObserver extends BaseAuthObserver { | ||
constructor() { | ||
super(...arguments); | ||
this.session = new DefaultAuthSession(); | ||
} | ||
update(action) { | ||
switch (action.action) { | ||
case AuthActions.SignInFailed: | ||
case AuthActions.RefreshFailed: | ||
case AuthActions.LoadTokenFromStorageFailed: | ||
this.session.error = action.error; | ||
this.session.token = undefined; | ||
this.session.user = undefined; | ||
this.session.isAuthenticated = false; | ||
break; | ||
case AuthActions.SignInSuccess: | ||
case AuthActions.RefreshSuccess: | ||
case AuthActions.LoadTokenFromStorageSuccess: | ||
this.session.error = undefined; | ||
this.session.token = action.tokenResponse; | ||
this.session.isAuthenticated = true; | ||
break; | ||
case AuthActions.LoadUserInfoSuccess: | ||
this.session.error = undefined; | ||
this.session.user = action.user; | ||
break; | ||
case AuthActions.LoadUserInfoFailed: | ||
this.session.error = action.error; | ||
this.session.user = undefined; | ||
break; | ||
case AuthActions.SignOutSuccess: | ||
case AuthActions.Init: | ||
this.session = new DefaultAuthSession(); | ||
break; | ||
case AuthActions.SignOutFailed: | ||
this.session.error = action.error; | ||
break; | ||
} | ||
} | ||
} | ||
export class ConsoleLogObserver extends BaseAuthObserver { | ||
update(action) { | ||
console.log(action); | ||
} | ||
} |
Oops, something went wrong.