@obelisk/auth
Advanced tools
Comparing version 1.6.2 to 1.7.0
@@ -7,4 +7,4 @@ import { AuthEvent, ObeliskAuth } from './auth'; | ||
private eventHandler; | ||
private storage; | ||
constructor(config: ObeliskConfig, eventHandler?: (event: AuthEvent) => void); | ||
private findIdTokenString; | ||
/** | ||
@@ -45,16 +45,12 @@ * @inheritdoc | ||
*/ | ||
setRememberMe(rememberMe: boolean): void; | ||
getLoginUrl(rememberMe: boolean, state?: string): Promise<string>; | ||
getLoginBody(rememberMe: boolean, state?: string): Promise<any>; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
getLoginUrl(state?: string): Promise<string>; | ||
getLoginBody(state?: string): Promise<any>; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
handleCodeExchange<T extends { | ||
url: string; | ||
}>(event: T): Promise<string>; | ||
private saveCodeVerifier; | ||
private loadCodeVerifier; | ||
private pushCodeVerifier; | ||
private popCodeVerifier; | ||
private setConfigDefaults; | ||
@@ -61,0 +57,0 @@ private getCodeChallenge; |
@@ -33,7 +33,2 @@ import { ObeliskConfig, Tokens } from './types'; | ||
/** | ||
* Remember your auth session over an extended period of time. | ||
* @param rememberMe | ||
*/ | ||
setRememberMe(rememberMe: boolean): void; | ||
/** | ||
* Checks if there is an idToken found in memory. This is only usefull to skip authenticating the user, | ||
@@ -45,7 +40,13 @@ * it does not mean that the user is logged in to Obelisk. | ||
* Returns the login url as a promise. Use this url to login. | ||
* @param rememberMe Remember your auth session over an extended period of time. | ||
* @param state A state paramters that will be returned to the registered redirectUri after logging in. | ||
*/ | ||
getLoginUrl(state?: string): Promise<string>; | ||
getLoginBody(state?: string): Promise<any>; | ||
getLoginUrl(rememberMe: boolean, state?: string): Promise<string>; | ||
/** | ||
* Returns the required login body as a promise. Use this body to post a login. | ||
* @param rememberMe Remember your auth session over an extended period of time. | ||
* @param state A state paramters that will be returned to the registered redirectUri after logging in. | ||
*/ | ||
getLoginBody(rememberMe: boolean, state?: string): Promise<any>; | ||
/** | ||
* Handler for detecting and exchanging an authorization code parameter in the querystring of the uri. | ||
@@ -52,0 +53,0 @@ * It will use it to retrieve the actual token. |
@@ -267,7 +267,7 @@ var AuthEventType; | ||
var KEY_ID_TOK = 'obelisk:idTok'; | ||
var KEY_CODE_VERIFIER = 'obelisk:codeVerifier'; | ||
var ObeliskAuthClient = /** @class */ (function () { | ||
function ObeliskAuthClient(config, eventHandler) { | ||
this.storage = sessionStorage; | ||
this.config = this.setConfigDefaults(config); | ||
var idTokenString = this.storage.getItem(KEY_ID_TOK); | ||
var idTokenString = this.findIdTokenString(); | ||
this.tokens = {}; | ||
@@ -280,2 +280,8 @@ if (idTokenString) { | ||
} | ||
ObeliskAuthClient.prototype.findIdTokenString = function () { | ||
// Search in remembered local storage first | ||
var tok = localStorage.getItem(KEY_ID_TOK); | ||
// If not found, also local in sessionStorage (noremember) | ||
return tok === null ? sessionStorage.getItem(KEY_ID_TOK) : tok; | ||
}; | ||
/** | ||
@@ -324,3 +330,5 @@ * @inheritdoc | ||
ObeliskAuthClient.prototype.logout = function () { | ||
this.storage.removeItem(KEY_ID_TOK); | ||
localStorage.removeItem(KEY_ID_TOK); | ||
sessionStorage.removeItem(KEY_ID_TOK); | ||
sessionStorage.removeItem(KEY_CODE_VERIFIER); | ||
this.tokens = {}; | ||
@@ -337,9 +345,3 @@ }; | ||
*/ | ||
ObeliskAuthClient.prototype.setRememberMe = function (rememberMe) { | ||
this.storage = rememberMe ? localStorage : sessionStorage; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
ObeliskAuthClient.prototype.getLoginUrl = function (state) { | ||
ObeliskAuthClient.prototype.getLoginUrl = function (rememberMe, state) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -361,2 +363,3 @@ var queryFields, _a, _b, query; | ||
_a.code_challenge_method = 'S256', | ||
_a.remember_me = rememberMe, | ||
_a.state = state || encodeURIComponent(btoa('/')), | ||
@@ -372,3 +375,3 @@ _a); | ||
}; | ||
ObeliskAuthClient.prototype.getLoginBody = function (state) { | ||
ObeliskAuthClient.prototype.getLoginBody = function (rememberMe, state) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -389,2 +392,3 @@ var queryFields, _a; | ||
_a.code_challenge_method = 'S256', | ||
_a.remember_me = rememberMe, | ||
_a.state = state || encodeURIComponent(btoa('/')), | ||
@@ -419,3 +423,3 @@ _a); | ||
query_1.grant_type = 'authorization_code'; | ||
query_1.code_verifier = this.loadCodeVerifier(); | ||
query_1.code_verifier = this.popCodeVerifier(); | ||
return fetch(this.getHostUrl() + this.getAuthPath() + '/token', { | ||
@@ -446,7 +450,9 @@ body: JSON.stringify(query_1), | ||
}; | ||
ObeliskAuthClient.prototype.saveCodeVerifier = function (verifier) { | ||
this.storage.setItem('obeliskCodeVerifier', verifier); | ||
ObeliskAuthClient.prototype.pushCodeVerifier = function (verifier) { | ||
sessionStorage.setItem(KEY_CODE_VERIFIER, verifier); | ||
}; | ||
ObeliskAuthClient.prototype.loadCodeVerifier = function () { | ||
return this.storage.getItem('obeliskCodeVerifier'); | ||
ObeliskAuthClient.prototype.popCodeVerifier = function () { | ||
var verifier = sessionStorage.getItem(KEY_CODE_VERIFIER); | ||
sessionStorage.removeItem(KEY_CODE_VERIFIER); | ||
return verifier; | ||
}; | ||
@@ -473,3 +479,3 @@ ObeliskAuthClient.prototype.setConfigDefaults = function (config) { | ||
codeChallenge = _a.apply(void 0, [_b.sent()]); | ||
this.saveCodeVerifier(codeVerifier); | ||
this.pushCodeVerifier(codeVerifier); | ||
return [2 /*return*/, Promise.resolve(codeChallenge)]; | ||
@@ -503,4 +509,7 @@ } | ||
if (tokenResponse.remember_me) { | ||
this.storage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
localStorage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
} | ||
else { | ||
sessionStorage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
} | ||
return res; | ||
@@ -507,0 +516,0 @@ }; |
@@ -270,7 +270,7 @@ 'use strict'; | ||
var KEY_ID_TOK = 'obelisk:idTok'; | ||
var KEY_CODE_VERIFIER = 'obelisk:codeVerifier'; | ||
var ObeliskAuthClient = /** @class */ (function () { | ||
function ObeliskAuthClient(config, eventHandler) { | ||
this.storage = sessionStorage; | ||
this.config = this.setConfigDefaults(config); | ||
var idTokenString = this.storage.getItem(KEY_ID_TOK); | ||
var idTokenString = this.findIdTokenString(); | ||
this.tokens = {}; | ||
@@ -283,2 +283,8 @@ if (idTokenString) { | ||
} | ||
ObeliskAuthClient.prototype.findIdTokenString = function () { | ||
// Search in remembered local storage first | ||
var tok = localStorage.getItem(KEY_ID_TOK); | ||
// If not found, also local in sessionStorage (noremember) | ||
return tok === null ? sessionStorage.getItem(KEY_ID_TOK) : tok; | ||
}; | ||
/** | ||
@@ -327,3 +333,5 @@ * @inheritdoc | ||
ObeliskAuthClient.prototype.logout = function () { | ||
this.storage.removeItem(KEY_ID_TOK); | ||
localStorage.removeItem(KEY_ID_TOK); | ||
sessionStorage.removeItem(KEY_ID_TOK); | ||
sessionStorage.removeItem(KEY_CODE_VERIFIER); | ||
this.tokens = {}; | ||
@@ -340,9 +348,3 @@ }; | ||
*/ | ||
ObeliskAuthClient.prototype.setRememberMe = function (rememberMe) { | ||
this.storage = rememberMe ? localStorage : sessionStorage; | ||
}; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
ObeliskAuthClient.prototype.getLoginUrl = function (state) { | ||
ObeliskAuthClient.prototype.getLoginUrl = function (rememberMe, state) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -364,2 +366,3 @@ var queryFields, _a, _b, query; | ||
_a.code_challenge_method = 'S256', | ||
_a.remember_me = rememberMe, | ||
_a.state = state || encodeURIComponent(btoa('/')), | ||
@@ -375,3 +378,3 @@ _a); | ||
}; | ||
ObeliskAuthClient.prototype.getLoginBody = function (state) { | ||
ObeliskAuthClient.prototype.getLoginBody = function (rememberMe, state) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -392,2 +395,3 @@ var queryFields, _a; | ||
_a.code_challenge_method = 'S256', | ||
_a.remember_me = rememberMe, | ||
_a.state = state || encodeURIComponent(btoa('/')), | ||
@@ -422,3 +426,3 @@ _a); | ||
query_1.grant_type = 'authorization_code'; | ||
query_1.code_verifier = this.loadCodeVerifier(); | ||
query_1.code_verifier = this.popCodeVerifier(); | ||
return fetch(this.getHostUrl() + this.getAuthPath() + '/token', { | ||
@@ -449,7 +453,9 @@ body: JSON.stringify(query_1), | ||
}; | ||
ObeliskAuthClient.prototype.saveCodeVerifier = function (verifier) { | ||
this.storage.setItem('obeliskCodeVerifier', verifier); | ||
ObeliskAuthClient.prototype.pushCodeVerifier = function (verifier) { | ||
sessionStorage.setItem(KEY_CODE_VERIFIER, verifier); | ||
}; | ||
ObeliskAuthClient.prototype.loadCodeVerifier = function () { | ||
return this.storage.getItem('obeliskCodeVerifier'); | ||
ObeliskAuthClient.prototype.popCodeVerifier = function () { | ||
var verifier = sessionStorage.getItem(KEY_CODE_VERIFIER); | ||
sessionStorage.removeItem(KEY_CODE_VERIFIER); | ||
return verifier; | ||
}; | ||
@@ -476,3 +482,3 @@ ObeliskAuthClient.prototype.setConfigDefaults = function (config) { | ||
codeChallenge = _a.apply(void 0, [_b.sent()]); | ||
this.saveCodeVerifier(codeVerifier); | ||
this.pushCodeVerifier(codeVerifier); | ||
return [2 /*return*/, Promise.resolve(codeChallenge)]; | ||
@@ -506,4 +512,7 @@ } | ||
if (tokenResponse.remember_me) { | ||
this.storage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
localStorage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
} | ||
else { | ||
sessionStorage.setItem(KEY_ID_TOK, tokenResponse.id_token); | ||
} | ||
return res; | ||
@@ -510,0 +519,0 @@ }; |
{ | ||
"name": "@obelisk/auth", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147626
1121