-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adb0d2a
commit 33179ba
Showing
8 changed files
with
294 additions
and
204 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,44 @@ | ||
import { Storage, after, fail } from '@noeldemartin/utils'; | ||
import { Authenticator, Solid } from '@aerogel/plugin-solid'; | ||
import type { AuthSession } from '@aerogel/plugin-solid'; | ||
|
||
const STORAGE_KEY = 'lss'; | ||
|
||
interface StorageData { | ||
loginUrl: string; | ||
} | ||
|
||
export default class LSSAuthenticator extends Authenticator { | ||
|
||
public async login(loginUrl: string): Promise<AuthSession> { | ||
Storage.set<StorageData>(STORAGE_KEY, { loginUrl }); | ||
|
||
// TODO support authentication without reloading | ||
location.reload(); | ||
|
||
// Browser should reload, so just make it wait for a while. | ||
await after({ seconds: 60 }); | ||
|
||
return fail('Browser should have reloaded, but it didn\'t'); | ||
} | ||
|
||
public async logout(): Promise<void> { | ||
Storage.remove(STORAGE_KEY); | ||
|
||
await this.endSession(); | ||
} | ||
|
||
protected async restoreSession(): Promise<void> { | ||
if (!Storage.has(STORAGE_KEY)) { | ||
return; | ||
} | ||
|
||
const { loginUrl } = Storage.require<StorageData>(STORAGE_KEY); | ||
const webId = `${loginUrl}/profile/card#me`; | ||
const user = await Solid.requireUserProfile(webId); | ||
|
||
await this.initAuthenticatedFetch(window.fetch.bind(window)); | ||
await this.startSession({ loginUrl, user }); | ||
} | ||
|
||
} |
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,11 @@ | ||
import LSSAuthenticator from '@/auth/LSSAuthenticator'; | ||
|
||
export const authenticators = { | ||
lss: new LSSAuthenticator(), | ||
}; | ||
|
||
export type RamenAuthenticators = typeof authenticators; | ||
|
||
declare module '@aerogel/plugin-solid' { | ||
interface Authenticators extends RamenAuthenticators {} | ||
} |
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
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
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
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