react-auth-kit
Advanced tools
Comparing version 3.0.0-alpha.20 to 3.0.0-alpha.21
{ | ||
"name": "react-auth-kit", | ||
"version": "3.0.0-alpha.20", | ||
"version": "3.0.0-alpha.21", | ||
"description": "Authentication Library for React, which makes Token based auth very easy", | ||
@@ -90,3 +90,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "360cd7be6c8d6c2f6d17684d9113094a02995a73" | ||
"gitHead": "1dfe96bb1dbaa9a9d856d4d30900bbba11838468" | ||
} |
@@ -10,37 +10,6 @@ /** | ||
import { AuthKitStateInterface, AuthKitSetState } from './types'; | ||
/** | ||
* @class TokenObject | ||
* | ||
* Stores and retrieve Token | ||
*/ | ||
declare class TokenObject<T> { | ||
private readonly authStorageName; | ||
private readonly stateStorageName; | ||
private readonly cookieDomain?; | ||
private readonly cookieSecure?; | ||
private readonly authStorageTypeName; | ||
private readonly authStorageType; | ||
private readonly refreshTokenName; | ||
private readonly isUsingRefreshToken; | ||
private authSubject; | ||
/** | ||
* TokenObject - Stores, retrieve and process tokens | ||
* | ||
* @param authStorageName - Name of the Token, | ||
* which will store the Authorization Token | ||
* | ||
* @param authStorageType - Type of the auth Storage, ` | ||
* cookie` or `localstorage` | ||
* | ||
* @param refreshTokenName - Name of the refresh Token, | ||
* if `undefined`, then no refreshToken feature is using | ||
* | ||
* @param cookieDomain - domain name for the Cookies, | ||
* only applicable when `authStorageType` is `cookie` | ||
* | ||
* @param cookieSecure - cookies are secure or not, | ||
* only applicable when `authStorageType` is `cookie` | ||
* | ||
* @constructor | ||
*/ | ||
private tokenObject; | ||
constructor(authStorageName: string, authStorageType: 'cookie' | 'localstorage', refreshTokenName: string | null, cookieDomain?: string, cookieSecure?: boolean); | ||
@@ -51,107 +20,3 @@ subscribe(next: ((value: AuthKitStateInterface<T>) => void), error?: ((err: any) => void)): void; | ||
get value(): AuthKitStateInterface<T>; | ||
/** | ||
* Get the Initial Tokens and states | ||
* Called externally in `AuthProvider` | ||
* when the Application is bootstrapping or refreshed | ||
* | ||
* If the `authStorageType` is `cookie`, | ||
* get information from `initialCookieToken()` function | ||
* | ||
* If the `authTokenType` is `localStorage` | ||
* get information from `initialLSToken()` function | ||
* | ||
* @returns AuthKitStateInterface | ||
*/ | ||
private initialToken_; | ||
/** | ||
* Get the Initial Token from Cookies | ||
* Called internally by `initialToken` method | ||
* | ||
* If the `authStorageType` is `cookie` | ||
* then this function is called | ||
* And returns the Tokens and states Stored in all 4 cookies | ||
* | ||
* @returns AuthKitStateInterface | ||
*/ | ||
private initialCookieToken_; | ||
/** | ||
* Get the Initial Token from LocalStorage | ||
* Called internally by `initialToken` method | ||
* | ||
* If the `authStorageType` is `localstorage` | ||
* then this function is called | ||
* And returns the Tokens and states Stored in all 4 cookies | ||
* | ||
* @returns AuthKitStateInterface | ||
*/ | ||
private initialLSToken_; | ||
/** | ||
* Check if the Initial token is valid or not, | ||
* Called Internally by `initialCookieToken_()` and `initialLSToken_()` | ||
* | ||
* If the tokens are valid, | ||
* then it response TokenObject with auth Information | ||
* Else it response TokenObject with all null | ||
* | ||
* @param authToken | ||
* @param authTokenType | ||
* @param authTokenTime | ||
* @param stateCookie | ||
* @param refreshToken | ||
* @param refreshTokenTime | ||
* | ||
* @returns AuthKitStateInterface | ||
* | ||
*/ | ||
private checkTokenExist_; | ||
private parseJwt_; | ||
private getExpireDateTime_; | ||
/** | ||
* Sync Auth Tokens on time of login and logout | ||
* | ||
* Set the New Cookies or new Localstorage on login | ||
* Or Remove the old Cookies or old Localstorage on logout | ||
* | ||
* @param authState | ||
*/ | ||
private syncTokens; | ||
private setAuthToken; | ||
private setRefreshToken; | ||
/** | ||
* Remove Tokens on time of Logout | ||
*/ | ||
private removeAllToken; | ||
/** | ||
* Remove Token from Cookies | ||
*/ | ||
private removeAllCookieToken_; | ||
/** | ||
* Remove Token from LocalStorage | ||
*/ | ||
private removeAllLSToken_; | ||
/** | ||
* Remove Tokens on time of Logout | ||
*/ | ||
private removeAuth; | ||
/** | ||
* Remove Token from Cookies | ||
*/ | ||
private removeAuthCookie; | ||
/** | ||
* Remove Token from LocalStorage | ||
*/ | ||
private removeAuthToken; | ||
/** | ||
* Remove Tokens on time of Logout | ||
*/ | ||
private removeRefresh; | ||
/** | ||
* Remove Token from Cookies | ||
*/ | ||
private removeRefreshCookie; | ||
/** | ||
* Remove Token from LocalStorage | ||
*/ | ||
private removeRefreshToken; | ||
} | ||
export default TokenObject; |
@@ -13,15 +13,6 @@ "use strict"; | ||
constructor(authStorageName, authStorageType, refreshTokenName, cookieDomain, cookieSecure) { | ||
this.authStorageName = authStorageName; | ||
this.authStorageType = authStorageType; | ||
this.stateStorageName = `${authStorageName}_state`; | ||
this.refreshTokenName = refreshTokenName; | ||
this.cookieDomain = cookieDomain; | ||
this.cookieSecure = cookieSecure; | ||
this.authStorageTypeName = `${this.authStorageName}_type`; | ||
this.isUsingRefreshToken = !!this.refreshTokenName; | ||
this.authSubject = new _rxjs.BehaviorSubject(this.initialToken_()); | ||
this.subscribe(this.syncTokens, err => { | ||
console.log("Error Happened"); | ||
console.log(err); | ||
}); | ||
this.isUsingRefreshToken = !!refreshTokenName; | ||
this.tokenObject = new InternalTokenObject(authStorageName = authStorageName, authStorageType = authStorageType, refreshTokenName = refreshTokenName, cookieDomain = cookieDomain, cookieSecure = cookieSecure); | ||
this.authSubject = new _rxjs.BehaviorSubject(this.tokenObject.initialToken_()); | ||
this.authSubject.subscribe(this.tokenObject.syncTokens); | ||
} | ||
@@ -49,3 +40,3 @@ subscribe(next, error) { | ||
'type': data.auth.type, | ||
'expiresAt': this.getExpireDateTime_(data.auth.token) | ||
'expiresAt': this.tokenObject.getExpireDateTime_(data.auth.token) | ||
}, | ||
@@ -69,3 +60,3 @@ isSignIn: true, | ||
'token': data.refresh, | ||
'expiresAt': this.getExpireDateTime_(data.refresh) | ||
'expiresAt': this.tokenObject.getExpireDateTime_(data.refresh) | ||
} | ||
@@ -87,2 +78,14 @@ }; | ||
} | ||
} | ||
class InternalTokenObject { | ||
constructor(authStorageName, authStorageType, refreshTokenName, cookieDomain, cookieSecure) { | ||
this.authStorageName = authStorageName; | ||
this.authStorageType = authStorageType; | ||
this.stateStorageName = `${authStorageName}_state`; | ||
this.refreshTokenName = refreshTokenName; | ||
this.cookieDomain = cookieDomain; | ||
this.cookieSecure = cookieSecure; | ||
this.authStorageTypeName = `${this.authStorageName}_type`; | ||
this.isUsingRefreshToken = !!this.refreshTokenName; | ||
} | ||
initialToken_() { | ||
@@ -89,0 +92,0 @@ if (this.authStorageType === 'cookie') { |
56328
1318