piral-oauth2
Version:
Plugin to integrate OAuth 2.0 authentication in Piral.
56 lines • 1.62 kB
JavaScript
/**
* Creates an OAuth 2 persistence layer using memory.
*/
export function createOAuth2MemoryPersistence() {
return {
load() {
return undefined;
},
save() { },
};
}
/**
* Creates an OAuth 2 persistence layer using sessionStorage.
*/
export function createOAuth2SessionPersistence(sessionKey = '$piral_oauth2_info') {
return {
load() {
const content = sessionStorage.getItem(sessionKey);
if (typeof content === 'string') {
try {
return JSON.parse(content);
}
catch {
console.error('Found invalid data in the OAuth 2 session storage key. Skipped.');
}
}
return undefined;
},
save(info) {
sessionStorage.setItem(sessionKey, JSON.stringify(info));
},
};
}
/**
* Creates an OAuth 2 persistence layer using localStorage.
*/
export function createOAuth2BrowserPersistence(localKey = '$piral_oauth2_info') {
return {
load() {
const content = localStorage.getItem(localKey);
if (typeof content === 'string') {
try {
return JSON.parse(content);
}
catch {
console.error('Found invalid data in the OAuth 2 local storage key. Skipped.');
}
}
return undefined;
},
save(info) {
localStorage.setItem(localKey, JSON.stringify(info));
},
};
}
//# sourceMappingURL=utils.js.map