@aerogel/plugin-solid 0.0.1-next.129b164cda8e791661ba16ad7bf51aaeae6be2eb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/InruptAuthenticator.lazy.hash.cjs.js +2 -0
- package/dist/InruptAuthenticator.lazy.hash.cjs.js.map +1 -0
- package/dist/InruptAuthenticator.lazy.hash.esm.js +2 -0
- package/dist/InruptAuthenticator.lazy.hash.esm.js.map +1 -0
- package/dist/aerogel-plugin-solid.cjs.js +2 -0
- package/dist/aerogel-plugin-solid.cjs.js.map +1 -0
- package/dist/aerogel-plugin-solid.d.ts +296 -0
- package/dist/aerogel-plugin-solid.esm.js +2 -0
- package/dist/aerogel-plugin-solid.esm.js.map +1 -0
- package/noeldemartin.config.js +5 -0
- package/package.json +52 -0
- package/src/auth/Authenticator.ts +123 -0
- package/src/auth/authenticators/InruptAuthenticator.lazy.ts +1 -0
- package/src/auth/authenticators/InruptAuthenticator.ts +103 -0
- package/src/auth/index.ts +38 -0
- package/src/components/AGSolidImage.vue +33 -0
- package/src/components/AGSolidStatus.ts +5 -0
- package/src/components/AGSolidStatus.vue +60 -0
- package/src/components/AGSolidUserAvatar.vue +35 -0
- package/src/components/index.ts +6 -0
- package/src/errors/AuthenticationCancelledError.ts +3 -0
- package/src/errors/AuthenticationFailedError.ts +22 -0
- package/src/errors/ContainerAlreadyInUse.ts +11 -0
- package/src/errors/index.ts +3 -0
- package/src/forms/validation.ts +11 -0
- package/src/main.ts +70 -0
- package/src/services/Solid.state.ts +56 -0
- package/src/services/Solid.ts +529 -0
- package/src/types/env.d.ts +1 -0
- package/src/types/shims.d.ts +7 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aerogel-plugin-solid.esm.js","sources":["../src/errors/AuthenticationCancelledError.ts","../src/errors/AuthenticationFailedError.ts","../src/errors/ContainerAlreadyInUse.ts","../src/auth/Authenticator.ts","../src/auth/authenticators/InruptAuthenticator.ts","../src/auth/index.ts","../src/services/Solid.state.ts","../src/services/Solid.ts","../src/components/AGSolidImage.vue","../src/components/AGSolidStatus.vue","../src/components/AGSolidUserAvatar.vue","../src/main.ts","../src/forms/validation.ts"],"sourcesContent":["import { JSError } from '@noeldemartin/utils';\n\nexport default class AuthenticationCancelledError extends JSError {}\n","import { JSError } from '@noeldemartin/utils';\nimport type { JSErrorOptions } from '@noeldemartin/utils';\n\nfunction getErrorMessage(message: string, description?: string | null): string {\n if (!description) {\n return message;\n }\n\n return `${message} (${description})`;\n}\n\nexport default class AuthenticationFailedError extends JSError {\n\n public readonly description?: string | null;\n\n constructor(message: string, description?: string | null, options?: JSErrorOptions) {\n super(getErrorMessage(message), options);\n\n this.description = description;\n }\n\n}\n","import { JSError } from '@noeldemartin/utils';\nimport type { JSErrorOptions } from '@noeldemartin/utils';\nimport type { SolidContainer } from 'soukai-solid';\n\nexport default class ContainerAlreadyInUse extends JSError {\n\n constructor(container: SolidContainer, options?: JSErrorOptions) {\n super(`Container at ${container.url} is already in use`, options);\n }\n\n}\n","import { PromisedValue, arr, fail } from '@noeldemartin/utils';\nimport { SolidEngine } from 'soukai-solid';\nimport type { Closure, FluentArray, GetClosureArgs } from '@noeldemartin/utils';\nimport type { Engine } from 'soukai';\nimport type { Fetch } from 'soukai-solid';\nimport type { SolidUserProfile } from '@noeldemartin/solid-utils';\nimport type { ErrorSource } from '@aerogel/core';\n\nimport type { AuthenticatorName } from '@/auth';\n\ntype ListenerEvent = keyof AuthenticatorListener;\ntype ListenerEventPayload<\n Event extends ListenerEvent,\n Callback = AuthenticatorListener[Event]\n> = Callback extends Closure ? GetClosureArgs<Callback> : never;\n\nexport interface AuthSession {\n user: SolidUserProfile;\n loginUrl: string;\n authenticator: Authenticator;\n}\n\nexport interface AuthenticatorListener {\n onSessionStarted?: (session: AuthSession) => Promise<void> | void;\n onSessionFailed?: (loginUrl: string, error: ErrorSource) => Promise<void> | void;\n onSessionEnded?: () => Promise<void> | void;\n onAuthenticatedFetchReady?: (fetch: Fetch) => Promise<void> | void;\n}\n\nexport default abstract class Authenticator {\n\n public name!: AuthenticatorName;\n\n protected authenticatedFetch?: Fetch;\n protected booted?: PromisedValue<void>;\n protected listeners: FluentArray<AuthenticatorListener> = arr<AuthenticatorListener>([]);\n protected _engine?: SolidEngine;\n\n public abstract login(loginUrl: string, user?: SolidUserProfile | null): Promise<AuthSession>;\n\n public abstract logout(): Promise<void>;\n\n public get engine(): Engine {\n this._engine = this._engine ?? new SolidEngine(this.requireAuthenticatedFetch());\n\n return this._engine;\n }\n\n public getAuthenticatedFetch(): Fetch | null {\n return this.authenticatedFetch ?? null;\n }\n\n public requireAuthenticatedFetch(): Fetch {\n return this.authenticatedFetch ?? fail('Authenticated fetch is not ready');\n }\n\n public addListener(listener: AuthenticatorListener): () => void {\n if (!this.listeners.includes(listener)) this.listeners.push(listener);\n\n return () => {\n this.removeListener(listener);\n };\n }\n\n public removeListener(listener: AuthenticatorListener): void {\n if (!this.listeners.includes(listener)) return;\n\n this.listeners.remove(listener);\n }\n\n public async boot(): Promise<void> {\n if (this.booted) {\n return this.booted;\n }\n\n this.booted = new PromisedValue();\n\n await this.restoreSession();\n\n this.booted.resolve();\n }\n\n protected abstract restoreSession(): Promise<void>;\n\n protected async initAuthenticatedFetch(fetch: Fetch): Promise<void> {\n this.authenticatedFetch = fetch;\n\n await this.notifyListeners('onAuthenticatedFetchReady', fetch);\n }\n\n protected async startSession(sessionData: Omit<AuthSession, 'authenticator'>): Promise<AuthSession> {\n const session: AuthSession = {\n authenticator: this,\n ...sessionData,\n };\n\n await this.notifyListeners('onSessionStarted', session);\n\n return session;\n }\n\n protected async failSession(loginUrl: string, error: ErrorSource): Promise<void> {\n await this.notifyListeners('onSessionFailed', loginUrl, error);\n }\n\n protected async endSession(): Promise<void> {\n await this.notifyListeners('onSessionEnded');\n }\n\n protected async notifyListeners<Event extends ListenerEvent>(\n event: Event,\n ...payload: ListenerEventPayload<Event>\n ): Promise<void> {\n await Promise.all(\n this.listeners.toArray().map(async (listener) => {\n const callback = listener[event] as Closure | undefined;\n\n await callback?.(...payload);\n }),\n );\n }\n\n}\n","import { Storage, after, fail } from '@noeldemartin/utils';\nimport type { Fetch } from 'soukai-solid';\nimport type {\n ILoginInputOptions,\n events,\n handleIncomingRedirect,\n login,\n logout,\n} from '@inrupt/solid-client-authn-browser';\n\nimport Authenticator from '@/auth/Authenticator';\nimport AuthenticationFailedError from '@/errors/AuthenticationFailedError';\nimport type { AuthSession } from '@/auth/Authenticator';\n\nimport AerogelSolid from 'virtual:aerogel-solid';\n\nconst STORAGE_KEY = 'inrupt-authenticator';\n\nexport default class InruptAuthenticator extends Authenticator {\n\n private _events!: typeof events;\n private _fetch!: Fetch;\n private _login!: typeof login;\n private _logout!: typeof logout;\n private _handleIncomingRedirect!: typeof handleIncomingRedirect;\n\n public async login(loginUrl: string): Promise<AuthSession> {\n Storage.set<string>(STORAGE_KEY, loginUrl);\n\n const options: ILoginInputOptions = {\n oidcIssuer: loginUrl,\n };\n\n if (AerogelSolid.clientID) {\n options.clientId = AerogelSolid.clientID.client_id;\n options.clientName = AerogelSolid.clientID.client_name;\n options.redirectUrl = AerogelSolid.clientID.redirect_uris[0];\n }\n\n await this._login(options);\n\n // Browser should redirect, so just make it wait for a while.\n await after({ seconds: 60 });\n\n return fail('Browser should have redirected, but it didn\\'t');\n }\n\n public async logout(): Promise<void> {\n await this._logout();\n await this.endSession();\n }\n\n protected async restoreSession(): Promise<void> {\n const { events, fetch, handleIncomingRedirect, login, logout } = await import('./InruptAuthenticator.lazy');\n\n this._fetch = fetch;\n this._login = login;\n this._logout = logout;\n this._events = events;\n this._handleIncomingRedirect = handleIncomingRedirect;\n\n await this.loginFromRedirect();\n }\n\n protected async loginFromRedirect(): Promise<void> {\n const loginUrl = Storage.get<string>(STORAGE_KEY);\n if (!loginUrl) {\n return;\n }\n\n this._events().on('error', (error: string | null, errorDescription?: string | Error | null) => {\n error ??= 'Error using Inrupt Authenticator method';\n\n if (typeof errorDescription === 'object') {\n this.failSession(loginUrl, new AuthenticationFailedError(error, null, { cause: errorDescription }));\n } else {\n this.failSession(loginUrl, new AuthenticationFailedError(error, errorDescription));\n }\n });\n\n const session = await this._handleIncomingRedirect(globalThis.location.href);\n\n Storage.remove(STORAGE_KEY);\n\n if (session?.isLoggedIn && session.webId) {\n await this.initSession(session.webId);\n }\n }\n\n protected async initSession(webId: string): Promise<void> {\n await this.initAuthenticatedFetch(this._fetch);\n\n try {\n const { default: Solid } = await import('@/services/Solid');\n const user = await Solid.requireUserProfile(webId);\n\n await this.startSession({ user, loginUrl: webId });\n } catch (error) {\n await this.failSession(webId, error);\n }\n }\n\n}\n","import InruptAuthenticator from './authenticators/InruptAuthenticator';\nimport type Authenticator from './Authenticator';\n\nconst _authenticators = {} as Authenticators;\n\ntype BaseAuthenticators = typeof authenticators;\n\nexport * from './Authenticator';\nexport { default as Authenticator } from './Authenticator';\n\nexport const authenticators = {\n inrupt: new InruptAuthenticator(),\n};\n\nexport function setDefaultAuthenticator(authenticator: Authenticator): void {\n _authenticators.default = authenticator;\n}\n\nexport function getAuthenticator<T extends AuthenticatorName>(name: T): Authenticators[T] {\n return _authenticators[name];\n}\n\nexport function registerAuthenticators(customAuthenticators: Record<string, Authenticator>): void {\n Object.entries(customAuthenticators).forEach(([name, authenticator]) =>\n registerAuthenticator(name as AuthenticatorName, authenticator));\n}\n\nexport function registerAuthenticator<T extends AuthenticatorName>(name: T, authenticator: Authenticators[T]): void {\n _authenticators[name] = authenticator;\n\n authenticator.name = authenticator.name ?? name;\n}\n\nexport type AuthenticatorName = keyof Authenticators;\n\nexport interface Authenticators extends BaseAuthenticators {\n default: Authenticator;\n}\n","import { defineServiceState } from '@aerogel/core';\nimport type { ErrorSource } from '@aerogel/core';\nimport type { Fetch, SolidUserProfile } from '@noeldemartin/solid-utils';\n\nimport type { AuthSession } from '@/auth/Authenticator';\nimport type { AuthenticatorName } from '@/auth';\n\nexport const DEFAULT_STATE = { autoReconnect: true };\n\nexport default defineServiceState({\n name: 'solid',\n persist: ['autoReconnect', 'dismissed', 'previousSession', 'profiles', 'staleProfiles'],\n initialState: {\n autoReconnect: DEFAULT_STATE.autoReconnect,\n dismissed: false,\n ignorePreviousSessionError: false,\n loginStartupError: null as ErrorSource | null,\n loginOngoing: false,\n preferredAuthenticator: null as AuthenticatorName | null,\n previousSession: null as {\n profile?: SolidUserProfile;\n authenticator: AuthenticatorName;\n loginUrl: string;\n error: ErrorSource | null;\n } | null,\n profiles: {} as Record<string, SolidUserProfile>,\n session: null as AuthSession | null,\n loginStale: false,\n staleProfiles: [] as string[],\n },\n serialize(state) {\n if (state.previousSession?.error instanceof Error) {\n state.previousSession.error = state.previousSession.error.message;\n }\n\n return state;\n },\n computed: {\n user: (state) => state.session?.user ?? state.previousSession?.profile ?? null,\n authenticator: (state) => state.session?.authenticator ?? null,\n fetch(): Fetch {\n return this.authenticator?.getAuthenticatedFetch() ?? globalThis.fetch.bind(globalThis);\n },\n error(state): ErrorSource | null {\n if (state.loginStartupError) {\n return state.loginStartupError ?? null;\n }\n\n if (state.ignorePreviousSessionError) {\n return null;\n }\n\n return state.previousSession?.error ?? null;\n },\n },\n});\n","import {\n after,\n arrayFilter,\n arrayUnique,\n arrayWithout,\n asyncMemo,\n facade,\n fail,\n getLocationQueryParameter,\n hasLocationQueryParameter,\n objectWithout,\n objectWithoutEmpty,\n parseBoolean,\n requireUrlParse,\n setAsyncMemo,\n tap,\n urlRoot,\n} from '@noeldemartin/utils';\nimport { App, Colors, Errors, Events, UI, translateWithDefault } from '@aerogel/core';\nimport { fetchLoginUserProfile } from '@noeldemartin/solid-utils';\nimport { setEngine } from 'soukai';\nimport { SolidACLAuthorization, SolidContainer, SolidDocument, SolidTypeIndex } from 'soukai-solid';\nimport type { ErrorSource } from '@aerogel/core';\nimport type { Fetch, SolidModelConstructor } from 'soukai-solid';\nimport type { SolidStore, SolidUserProfile } from '@noeldemartin/solid-utils';\n\nimport AuthenticationCancelledError from '@/errors/AuthenticationCancelledError';\nimport { ContainerAlreadyInUse } from '@/errors';\nimport { getAuthenticator } from '@/auth';\nimport type Authenticator from '@/auth/Authenticator';\nimport type { AuthenticatorName } from '@/auth';\nimport type { AuthSession } from '@/auth/Authenticator';\n\nimport Service, { DEFAULT_STATE } from './Solid.state';\n\nexport type LoginOptions = {\n authenticator?: AuthenticatorName;\n onError?(error: ErrorSource): unknown;\n fallbackUrl?: string;\n loading?: boolean;\n};\n\nexport type ReconnectOptions = Omit<LoginOptions, 'authenticator'> & {\n force?: boolean;\n};\n\nexport class SolidService extends Service {\n\n public isLoggedIn(): this is { session: AuthSession; user: SolidUserProfile; authenticator: Authenticator } {\n return !!this.session;\n }\n\n public wasLoggedIn(): this is { user: SolidUserProfile } {\n return !!this.previousSession;\n }\n\n public hasLoggedIn(): this is { user: SolidUserProfile } {\n return !!(this.session || this.previousSession);\n }\n\n public requireAuthenticator(): Authenticator {\n return this.authenticator ?? fail('Could not get authenticator');\n }\n\n public requireUser(): SolidUserProfile {\n return this.user ?? fail('Could not get user profile (are you logged in?)');\n }\n\n public requireUserProfile(url: string): Promise<SolidUserProfile> {\n return this.getUserProfile(url, true);\n }\n\n public async getUserProfile(url: string, required: true): Promise<SolidUserProfile>;\n public async getUserProfile(url: string, required?: false): Promise<SolidUserProfile | null>;\n public async getUserProfile(url: string, required: boolean = false): Promise<SolidUserProfile | null> {\n let profileStore: SolidStore | null = null;\n const usingAuthenticatedFetch = !!this.authenticator?.getAuthenticatedFetch();\n\n return (\n this.profiles[url] ??\n tap(\n await fetchLoginUserProfile(url, {\n fetch: this.fetch,\n required,\n onLoaded(store) {\n profileStore = store;\n },\n }),\n async (profile) => {\n if (!profile) {\n return;\n }\n\n if (profileStore) {\n await Events.emit('solid:user-profile-loaded', [profile, profileStore]);\n }\n\n this.rememberProfile(profile);\n\n if (!usingAuthenticatedFetch) {\n this.setState({ staleProfiles: arrayUnique(this.staleProfiles.concat([profile.webId])) });\n }\n },\n )\n );\n }\n\n public async refreshUserProfile(): Promise<void> {\n if (!this.isLoggedIn()) {\n return;\n }\n\n this.setState({ profiles: objectWithout(this.profiles, [this.user.webId]) });\n\n const user = await this.requireUserProfile(this.user.webId);\n\n this.setState({\n session: {\n ...this.session,\n user,\n },\n });\n }\n\n public async login(loginUrl: string, options: LoginOptions = {}): Promise<boolean> {\n if (App.development && loginUrl === 'dev') {\n loginUrl = 'http://localhost:3000';\n }\n\n if (!/^https?:\\/\\//.test(loginUrl)) {\n options.fallbackUrl ??= `http://${loginUrl}`;\n loginUrl = `https://${loginUrl}`;\n }\n\n if (this.isLoggedIn()) {\n return true;\n }\n\n if (this.loginOngoing) {\n throw new Error('Authentication already in progress');\n }\n\n if (!options.loading) {\n return this.attemptLogin(loginUrl, options);\n }\n\n return UI.loading(translateWithDefault('solid.loggingIn', 'Logging in...'), () => {\n return this.attemptLogin(loginUrl, options);\n });\n }\n\n public async reconnect(options: ReconnectOptions = {}): Promise<void> {\n const { force, ...loginOptions } = options;\n if (this.isLoggedIn() || !this.previousSession || (this.previousSession.error !== null && !force)) {\n return;\n }\n\n await this.login(this.previousSession.loginUrl, {\n authenticator: this.previousSession.authenticator,\n ...loginOptions,\n loading: loginOptions.loading ?? false,\n });\n }\n\n public async logout(force: boolean = false): Promise<void> {\n const isCloudReady = !App.plugin('@aerogel/offline-first') || !!App.service('$cloud')?.ready;\n const hasLocalChanges = !App.plugin('@aerogel/offline-first') || !!App.service('$cloud')?.dirty;\n const [confirmLogout, options] = force\n ? [true, { wipeLocalData: isCloudReady }]\n : await UI.confirm(\n isCloudReady\n ? translateWithDefault('solid.logoutConfirmTitle', 'Log out from this device?')\n : translateWithDefault('solid.disconnectConfirmTitle', 'Disconnect account?'),\n isCloudReady\n ? hasLocalChanges\n ? translateWithDefault(\n 'solid.logoutConfirmMessageWithLocalChanges',\n 'There are some changes that haven\\'t been synchronized and will be lost, ' +\n 'but the rest of the data will remain in your Solid POD.',\n )\n : translateWithDefault(\n 'solid.logoutConfirmMessage',\n 'Logging out will remove all the data from this device, ' +\n 'but you\\'ll still have it in your Solid POD.',\n )\n : translateWithDefault(\n 'solid.disconnectConfirmMessage',\n 'You\\'ll need to introduce logging details again to connect to your Solid POD.',\n ),\n {\n acceptText: translateWithDefault('solid.logoutConfirmAccept', 'Log out'),\n acceptColor: Colors.Danger,\n cancelText: translateWithDefault(\n 'solid.logoutConfirmCancel',\n translateWithDefault('ui.cancel', 'Cancel'),\n ),\n checkboxes: isCloudReady\n ? hasLocalChanges\n ? {\n wipeLocalData: {\n label: translateWithDefault(\n 'solid.logoutConfirmWipeNotice',\n 'I understand that changes that haven\\'t been synchronized will be lost.',\n ),\n default: false,\n required: true,\n },\n }\n : undefined\n : {\n wipeLocalData: {\n label: translateWithDefault(\n 'solid.logoutConfirmWipe',\n 'Also remove all existing data (tasks, lists, etc.)',\n ),\n default: false,\n },\n },\n },\n );\n\n if (!confirmLogout) {\n return;\n }\n\n if (!this.previousSession) {\n return;\n }\n\n await UI.loading(translateWithDefault('solid.logoutOngoing', 'Logging out...'), async () => {\n this.setState({\n dismissed: false,\n ignorePreviousSessionError: false,\n loginStartupError: null,\n previousSession: null,\n ...DEFAULT_STATE,\n });\n\n this.isLoggedIn() && (await this.authenticator.logout());\n\n await Events.emit('auth:logout', { wipeLocalData: options.wipeLocalData ?? true });\n await Events.emit('auth:after-logout');\n });\n }\n\n public async whenLoggedIn<T>(callback: (session: AuthSession) => T): Promise<T> {\n if (this.isLoggedIn()) {\n return callback(this.session);\n }\n\n return new Promise((resolve) => {\n const onLogin = (session: AuthSession) => resolve(callback(session));\n\n Events.once('auth:login', onLogin);\n });\n }\n\n public dismiss(): void {\n this.setState({ dismissed: true });\n }\n\n public async findOrCreatePrivateTypeIndex(): Promise<SolidTypeIndex> {\n return (await this.findPrivateTypeIndex()) ?? (await this.createPrivateTypeIndex());\n }\n\n public async findPrivateTypeIndex(): Promise<SolidTypeIndex | null> {\n const { webId, privateTypeIndexUrl } = this.requireUser();\n const engine = this.requireAuthenticator().engine;\n\n if (!privateTypeIndexUrl) {\n return null;\n }\n\n return asyncMemo(`${webId}-privateTypeIndex`, () =>\n SolidTypeIndex.withEngine(engine).find(privateTypeIndexUrl));\n }\n\n public async findOrCreatePublicTypeIndex(): Promise<SolidTypeIndex> {\n return (await this.findPublicTypeIndex()) ?? (await this.createPublicTypeIndex());\n }\n\n public async findPublicTypeIndex(): Promise<SolidTypeIndex | null> {\n const { webId, publicTypeIndexUrl } = this.requireUser();\n const engine = this.requireAuthenticator().engine;\n\n if (!publicTypeIndexUrl) {\n return null;\n }\n\n return asyncMemo(`${webId}-publicTypeIndex`, () => SolidTypeIndex.withEngine(engine).find(publicTypeIndexUrl));\n }\n\n public async createPrivateContainer(options: {\n url: string;\n name?: string;\n registerFor?: SolidModelConstructor;\n reuseExisting?: boolean;\n }): Promise<SolidContainer> {\n const engine = this.requireAuthenticator().engine;\n\n return SolidContainer.withEngine(engine, async () => {\n const existingContainer = await SolidContainer.find(options.url);\n\n if (existingContainer && !options.reuseExisting) {\n throw new ContainerAlreadyInUse(existingContainer);\n }\n\n const container = existingContainer ?? new SolidContainer({ url: options.url, name: options.name });\n\n await container.save();\n\n if (options.registerFor) {\n const typeIndex = await this.findOrCreatePrivateTypeIndex();\n\n await container.register(typeIndex, options.registerFor);\n }\n\n return container;\n });\n }\n\n protected async boot(): Promise<void> {\n await Errors.booted;\n\n if (hasLocationQueryParameter('authenticator')) {\n this.setState({\n preferredAuthenticator: getLocationQueryParameter('authenticator') as AuthenticatorName,\n });\n }\n\n if (hasLocationQueryParameter('refreshProfile')) {\n this.setState({\n staleProfiles: arrayUnique(\n this.staleProfiles.concat(arrayFilter([this.session?.user.webId, this.previousSession?.loginUrl])),\n ),\n });\n }\n\n await this.restorePreviousSession();\n await this.startupReconnect();\n }\n\n protected async createPrivateTypeIndex(): Promise<SolidTypeIndex> {\n const user = this.requireUser();\n const authenticator = this.requireAuthenticator();\n const typeIndex = await SolidTypeIndex.withEngine(authenticator.engine).createPrivate(user);\n\n return tap(typeIndex, () => {\n user.privateTypeIndexUrl = typeIndex.url;\n\n setAsyncMemo(`${user.webId}-privateTypeIndex`, typeIndex);\n\n this.rememberProfile(user);\n });\n }\n\n public async createPublicTypeIndex(): Promise<SolidTypeIndex> {\n const user = this.requireUser();\n const authenticator = this.requireAuthenticator();\n const typeIndex = await SolidTypeIndex.withEngine(authenticator.engine).createPublic(user);\n\n return tap(typeIndex, () => {\n user.privateTypeIndexUrl = typeIndex.url;\n\n setAsyncMemo(`${user.webId}-publicTypeIndex`, typeIndex);\n\n this.rememberProfile(user);\n });\n }\n\n protected async attemptLogin(loginUrl: string, options: LoginOptions): Promise<boolean> {\n const authenticatorName = options.authenticator ?? this.preferredAuthenticator ?? 'default';\n const handleLoginError =\n options.onError ??\n ((error: ErrorSource) =>\n App.isMounted() ? Errors.report(error) : this.setState({ loginStartupError: error }));\n const staleTimeout = setTimeout(() => (this.loginStale = true), 10000);\n const initialState = {\n dismissed: this.dismissed,\n ignorePreviousSessionError: this.ignorePreviousSessionError,\n previousSession: this.previousSession,\n };\n this.loginOngoing = true;\n\n try {\n const profile = await this.getUserProfile(loginUrl);\n const oidcIssuerUrl = profile?.oidcIssuerUrl ?? urlRoot(profile?.webId ?? loginUrl);\n const authenticator = await this.bootAuthenticator(authenticatorName);\n const { domain: loginDomain } = requireUrlParse(loginUrl);\n\n this.setState({\n dismissed: false,\n ignorePreviousSessionError: true,\n previousSession: objectWithoutEmpty({\n profile,\n loginUrl,\n authenticator: authenticatorName,\n error: translateWithDefault(\n 'auth.stuckConnecting',\n `We didn't hear back from the identity provider at \\`${loginDomain}\\`, maybe try reconnecting?`,\n ),\n }),\n });\n\n await Events.emit('auth:before-login');\n\n // This should redirect away from the app, so in most cases\n // the rest of the code won't be reached.\n await authenticator.login(oidcIssuerUrl, profile);\n\n return true;\n } catch (error) {\n this.setState(initialState);\n\n if (error instanceof AuthenticationCancelledError) {\n return false;\n }\n\n if (options.fallbackUrl) {\n return after().then(() => this.login(options.fallbackUrl ?? '', objectWithout(options, 'fallbackUrl')));\n }\n\n handleLoginError(error);\n\n return false;\n } finally {\n clearTimeout(staleTimeout);\n\n this.setState({\n loginOngoing: false,\n loginStale: false,\n });\n }\n }\n\n private async restorePreviousSession(): Promise<void> {\n if (!this.previousSession) {\n return;\n }\n\n await this.bootAuthenticator(this.previousSession.authenticator);\n }\n\n private async startupReconnect(): Promise<void> {\n if (!this.reconnectOnStartup()) {\n return;\n }\n\n await this.reconnect();\n }\n\n private reconnectOnStartup(): boolean {\n if (hasLocationQueryParameter('autoReconnect')) {\n return parseBoolean(getLocationQueryParameter('autoReconnect'));\n }\n\n return this.autoReconnect;\n }\n\n private async bootAuthenticator(name: AuthenticatorName): Promise<Authenticator> {\n const authenticator = getAuthenticator(name);\n\n authenticator.addListener({\n onSessionStarted: async (session) => {\n this.setState({\n session,\n previousSession: {\n authenticator: authenticator.name,\n loginUrl: session.loginUrl,\n profile: session.user,\n error: null,\n },\n });\n\n if (this.staleProfiles.includes(session.user.webId)) {\n await this.refreshUserProfile();\n }\n\n App.plugin('@aerogel/offline-first') || setEngine(session.authenticator.engine);\n\n SolidACLAuthorization.setEngine(session.authenticator.engine);\n SolidTypeIndex.setEngine(session.authenticator.engine);\n SolidDocument.setEngine(session.authenticator.engine);\n\n await Events.emit('auth:login', session);\n },\n onSessionFailed: async (loginUrl, error) => {\n this.setState({\n session: null,\n previousSession: {\n authenticator: authenticator.name,\n loginUrl,\n error,\n },\n });\n },\n onSessionEnded: () => this.setState({ session: null }),\n onAuthenticatedFetchReady: (fetch) => Events.emit('auth:fetch-ready', fetch),\n });\n\n await authenticator.boot();\n\n return authenticator;\n }\n\n private rememberProfile(profile: SolidUserProfile): void {\n this.setState({\n profiles: {\n ...this.profiles,\n [profile.webId]: profile,\n },\n staleProfiles: arrayWithout(this.staleProfiles, profile.webId),\n });\n }\n\n}\n\nexport default facade(SolidService);\n\ndeclare module '@aerogel/core' {\n export interface EventsPayload {\n 'auth:fetch-ready': Fetch;\n 'auth:before-login': void;\n 'auth:login': AuthSession;\n 'auth:logout': { wipeLocalData: boolean };\n 'auth:after-logout': void;\n 'solid:user-profile-loaded': [SolidUserProfile, SolidStore];\n }\n}\n","<template>\n <img :src=\"sourceUrl\">\n</template>\n\n<script setup lang=\"ts\">\nimport { Cache, computedAsync, requiredStringProp } from '@aerogel/core';\n\nimport Solid from '@/services/Solid';\n\nconst props = defineProps({ src: requiredStringProp() });\nconst sourceUrl = computedAsync(async () => {\n const cachedResponse = (await Cache.get(props.src)) ?? (await downloadImage(props.src));\n const blob = await cachedResponse?.blob();\n\n return blob && URL.createObjectURL(blob);\n});\n\nasync function downloadImage(url: string) {\n try {\n const response = await Solid.fetch(url);\n\n if (response.status !== 200) {\n return null;\n }\n\n await Cache.store(url, response);\n\n return Cache.get(url);\n } catch (error) {\n return null;\n }\n}\n</script>\n","<template>\n <div>\n <slot v-if=\"$solid.loginStale\" name=\"login-stale\">\n <AGMarkdown :text=\"$td('solid.loginStale', 'This is taking too long...')\" />\n </slot>\n\n <slot v-if=\"$solid.loginOngoing\" name=\"login-ongoing\">\n <AGMarkdown :text=\"$td('ui.loading', 'Loading...')\" />\n </slot>\n\n <slot v-else-if=\"$solid.isLoggedIn()\" name=\"logged-in\" :session=\"$solid.session\">\n <div class=\"flex flex-col gap-3\">\n <AGMarkdown\n :text=\"\n $td('solid.loggedIn', 'You are logged in as [{userName}]({userWebId})', {\n userName: $solid.user.name ?? $solid.user.webId,\n userWebId: $solid.user.webId,\n })\n \"\n />\n <AGButton @click=\"$solid.logout()\">\n {{ $td('solid.logout', 'Logout') }}\n </AGButton>\n </div>\n </slot>\n\n <slot v-else name=\"logged-out\">\n <div class=\"flex flex-col\">\n <AGForm :form=\"form\" class=\"flex\" @submit=\"$solid.login(form.url)\">\n <AGInput\n name=\"url\"\n :aria-label=\"$td('solid.url', 'Login url')\"\n :placeholder=\"$td('solid.placeholder', 'https://...')\"\n />\n <AGButton submit>\n {{ $td('solid.login', 'Login') }}\n </AGButton>\n </AGForm>\n <AGButton v-if=\"$solid.wasLoggedIn()\" class=\"mt-3\" @click=\"$solid.reconnect({ force: true })\">\n {{ $td('solid.reconnect', 'Reconnect') }}\n </AGButton>\n <p\n v-if=\"$solid.previousSession?.error || $solid.loginStartupError\"\n class=\"mt-1 self-center text-sm text-red-800\"\n >\n <AGMarkdown :text=\"$td('solid.previousLoginError', 'Previous login attempt failed')\" inline />\n <AGLink @click=\"$errors.inspect($solid.previousSession?.error || $solid.loginStartupError)\">\n ({{ $td('errors.viewDetails', 'View details') }})\n </AGLink>\n </p>\n </div>\n </slot>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { AGButton, AGForm, AGInput, AGLink, AGMarkdown, requiredStringInput, useForm } from '@aerogel/core';\n\nconst form = useForm({ url: requiredStringInput() });\n</script>\n","<template>\n <div class=\"relative flex items-center justify-center rounded-full bg-gray-200\">\n <AGSolidImage\n v-if=\"$solid.user?.avatarUrl\"\n :src=\"$solid.user?.avatarUrl\"\n alt=\"\"\n class=\"absolute inset-0 h-full w-full rounded-full\"\n />\n <span v-else-if=\"userInitials\" class=\"text-sm font-semibold tracking-wider text-gray-500\" aria-hidden=\"true\">\n {{ userInitials }}\n </span>\n <IconAnonymous v-else class=\"h-6 w-6 text-gray-500\" />\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport IconAnonymous from '~icons/ooui/user-anonymous';\n\nimport { computed } from 'vue';\n\nimport Solid from '@/services/Solid';\n\nimport AGSolidImage from './AGSolidImage.vue';\n\nconst userInitials = computed(() => {\n const name = Solid.user?.name ?? '';\n\n return name\n .trim()\n .split(' ')\n .map((part) => part[0]?.toUpperCase())\n .join('')\n .slice(0, 3);\n});\n</script>\n","import { Events, bootServices, registerErrorHandler } from '@aerogel/core';\nimport { bootSolidModels } from 'soukai-solid';\nimport type { Plugin } from '@aerogel/core';\nimport type { SolidStore, SolidUserProfile } from '@noeldemartin/solid-utils';\n\nimport Solid from '@/services/Solid';\nimport { DEFAULT_STATE } from '@/services/Solid.state';\nimport { defineFormValidationRules } from '@/forms/validation';\nimport {\n authenticators as baseAuthenticators,\n getAuthenticator,\n registerAuthenticators,\n setDefaultAuthenticator,\n} from '@/auth';\nimport { AuthenticationFailedError } from '@/errors';\nimport type Authenticator from '@/auth/Authenticator';\nimport type { AuthenticatorName } from '@/auth';\n\nconst services = { $solid: Solid };\n\nexport * from './auth';\nexport * from './components';\nexport * from './errors';\nexport * from './services/Solid';\nexport { Solid };\n\nexport interface Options {\n autoReconnect?: boolean;\n authenticators?: Record<string, Authenticator>;\n defaultAuthenticator?: AuthenticatorName;\n onUserProfileLoaded?(user: SolidUserProfile, store: SolidStore): Promise<unknown> | unknown;\n}\n\nexport type SolidServices = typeof services;\n\nexport default function solid(options: Options = {}): Plugin {\n return {\n async install(app) {\n bootSolidModels();\n registerAuthenticators({ ...baseAuthenticators, ...(options.authenticators ?? {}) });\n defineFormValidationRules();\n setDefaultAuthenticator(getAuthenticator(options.defaultAuthenticator ?? 'inrupt'));\n registerErrorHandler((error) => {\n if (!(error instanceof AuthenticationFailedError)) {\n return;\n }\n\n return error.description ? `${error.message} (${error.description})` : error.message;\n });\n\n if (typeof options.autoReconnect === 'boolean') {\n DEFAULT_STATE.autoReconnect = options.autoReconnect;\n\n Solid.hasPersistedState() || (Solid.autoReconnect = options.autoReconnect);\n }\n\n if (options.onUserProfileLoaded) {\n Events.on('solid:user-profile-loaded', ([user, store]) => {\n options.onUserProfileLoaded?.(user, store);\n });\n }\n\n await bootServices(app, services);\n },\n };\n}\n\ndeclare module '@aerogel/core' {\n interface Services extends SolidServices {}\n}\n","import { defineFormValidationRule } from '@aerogel/core';\n\nexport function defineFormValidationRules(): void {\n defineFormValidationRule<string>('container_url', (value) => {\n if (value.endsWith('/')) {\n return;\n }\n\n return 'containerEndingSlashMissing';\n });\n}\n"],"names":["AuthenticationCancelledError","JSError","AuthenticationFailedError","constructor","message","description","options","super","getErrorMessage","_defineProperty","this","ContainerAlreadyInUse","container","url","Authenticator","arr","engine","_engine","SolidEngine","requireAuthenticatedFetch","getAuthenticatedFetch","authenticatedFetch","fail","addListener","listener","listeners","includes","push","removeListener","remove","boot","booted","PromisedValue","restoreSession","resolve","initAuthenticatedFetch","fetch","notifyListeners","startSession","sessionData","session","authenticator","failSession","loginUrl","error","endSession","event","_len","arguments","length","payload","Array","_key","Promise","all","toArray","map","async","callback","STORAGE_KEY","_authenticators","authenticators","inrupt","login","Storage","set","oidcIssuer","AerogelSolid","clientID","clientId","client_id","clientName","client_name","redirectUrl","redirect_uris","_login","after","seconds","logout","_logout","events","handleIncomingRedirect","import","_fetch","_events","_handleIncomingRedirect","loginFromRedirect","get","on","errorDescription","cause","globalThis","location","href","isLoggedIn","webId","initSession","default","Solid","then","Solid$1","user","requireUserProfile","setDefaultAuthenticator","getAuthenticator","name","registerAuthenticators","customAuthenticators","Object","entries","forEach","_ref","registerAuthenticator","DEFAULT_STATE","autoReconnect","Service","defineServiceState","persist","initialState","dismissed","ignorePreviousSessionError","loginStartupError","loginOngoing","preferredAuthenticator","previousSession","profiles","loginStale","staleProfiles","serialize","state","Error","computed","profile","bind","SolidService","wasLoggedIn","hasLoggedIn","requireAuthenticator","requireUser","getUserProfile","required","profileStore","usingAuthenticatedFetch","tap","fetchLoginUserProfile","onLoaded","store","Events","emit","rememberProfile","setState","arrayUnique","concat","refreshUserProfile","objectWithout","App","development","test","fallbackUrl","loading","UI","translateWithDefault","attemptLogin","reconnect","undefined","force","loginOptions","isCloudReady","plugin","service","ready","hasLocalChanges","dirty","confirmLogout","wipeLocalData","confirm","acceptText","acceptColor","Colors","Danger","cancelText","checkboxes","label","whenLoggedIn","once","dismiss","findOrCreatePrivateTypeIndex","findPrivateTypeIndex","createPrivateTypeIndex","privateTypeIndexUrl","asyncMemo","SolidTypeIndex","withEngine","find","findOrCreatePublicTypeIndex","findPublicTypeIndex","createPublicTypeIndex","publicTypeIndexUrl","createPrivateContainer","SolidContainer","existingContainer","reuseExisting","save","registerFor","typeIndex","register","Errors","hasLocationQueryParameter","getLocationQueryParameter","arrayFilter","restorePreviousSession","startupReconnect","createPrivate","setAsyncMemo","createPublic","authenticatorName","handleLoginError","onError","isMounted","report","staleTimeout","setTimeout","oidcIssuerUrl","urlRoot","bootAuthenticator","domain","loginDomain","requireUrlParse","objectWithoutEmpty","clearTimeout","reconnectOnStartup","parseBoolean","onSessionStarted","setEngine","SolidACLAuthorization","SolidDocument","onSessionFailed","onSessionEnded","onAuthenticatedFetchReady","arrayWithout","facade","props","__props","sourceUrl","computedAsync","cachedResponse","Cache","src","response","status","downloadImage","blob","URL","createObjectURL","form","useForm","requiredStringInput","userInitials","trim","split","part","toUpperCase","join","slice","services","$solid","solid","install","app","bootSolidModels","baseAuthenticators","defineFormValidationRule","value","endsWith","defaultAuthenticator","registerErrorHandler","hasPersistedState","onUserProfileLoaded","bootServices"],"mappings":"y1DAEqB,MAAAA,qCAAqCC,GCSrC,MAAAC,kCAAkCD,EAInDE,WAAAA,CAAYC,EAAiBC,EAA6BC,GACtDC,MAbR,SAAyBH,EAAiBC,GACtC,OAAKA,EAIK,GAAAD,MAAYC,KAHXD,CAIf,CAOcI,CAAgBJ,GAAUE,GAASG,EAAAC,KAAA,mBAAA,GAEzCA,KAAKL,YAAcA,CACvB,ECfiB,MAAAM,WAA8BV,EAE/CE,WAAAA,CAAYS,EAA2BN,GACnCC,sBAAsBK,EAAUC,wBAAyBP,EAC7D,ECqBU,MAAgBQ,GAAaX,WAAAA,GAAAM,EAAAC,KAAA,YAAA,GAAAD,EAAAC,KAAA,0BAAA,GAAAD,EAAAC,KAAA,cAAA,GAAAD,EAMmBM,KAAAA,YAAAA,EAA2B,KAAGN,EAAAC,KAAA,eAAA,EAAA,CAOxF,UAAWM,GAGP,OAFAN,KAAKO,QAAUP,KAAKO,SAAW,IAAIC,EAAYR,KAAKS,6BAE7CT,KAAKO,OAChB,CAEOG,qBAAAA,GACH,OAAOV,KAAKW,oBAAsB,IACt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7bf51aaeae6be2eb",
|
|
5
|
+
"main": "dist/aerogel-plugin-solid.cjs.js",
|
|
6
|
+
"module": "dist/aerogel-plugin-solid.esm.js",
|
|
7
|
+
"types": "dist/aerogel-plugin-solid.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm dist -rf && npm run build:js && npm run build:types",
|
|
11
|
+
"build:js": "noeldemartin-build-javascript",
|
|
12
|
+
"build:types": "noeldemartin-build-types",
|
|
13
|
+
"publish-next": "noeldemartin-publish-next",
|
|
14
|
+
"lint": "noeldemartin-lint src"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.x"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/NoelDeMartin/aerogeljs.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"javascript",
|
|
25
|
+
"aerogel"
|
|
26
|
+
],
|
|
27
|
+
"author": "Noel De Martin",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/NoelDeMartin/aerogeljs/issues"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@aerogel/core": "*",
|
|
34
|
+
"@aerogel/vite": "*",
|
|
35
|
+
"soukai": "*",
|
|
36
|
+
"soukai-solid": "*"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@inrupt/solid-client-authn-browser": "^2.1.0",
|
|
40
|
+
"@noeldemartin/solid-utils": "0.4.0-next.bf5431cf569638e6dbc4cfd22c73be975e28f0a8",
|
|
41
|
+
"@noeldemartin/utils": "0.5.1-next.8877300615e6d56d7b5dfe508524589287835f23",
|
|
42
|
+
"vue": "^3.3.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@aerogel/plugin-offline-first": "0.0.0-next.cdd166d45dc23b4ffaf9b6e1c2a51db790c6b0d1"
|
|
46
|
+
},
|
|
47
|
+
"eslintConfig": {
|
|
48
|
+
"extends": [
|
|
49
|
+
"@noeldemartin/eslint-config-vue"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { PromisedValue, arr, fail } from '@noeldemartin/utils';
|
|
2
|
+
import { SolidEngine } from 'soukai-solid';
|
|
3
|
+
import type { Closure, FluentArray, GetClosureArgs } from '@noeldemartin/utils';
|
|
4
|
+
import type { Engine } from 'soukai';
|
|
5
|
+
import type { Fetch } from 'soukai-solid';
|
|
6
|
+
import type { SolidUserProfile } from '@noeldemartin/solid-utils';
|
|
7
|
+
import type { ErrorSource } from '@aerogel/core';
|
|
8
|
+
|
|
9
|
+
import type { AuthenticatorName } from '@/auth';
|
|
10
|
+
|
|
11
|
+
type ListenerEvent = keyof AuthenticatorListener;
|
|
12
|
+
type ListenerEventPayload<
|
|
13
|
+
Event extends ListenerEvent,
|
|
14
|
+
Callback = AuthenticatorListener[Event]
|
|
15
|
+
> = Callback extends Closure ? GetClosureArgs<Callback> : never;
|
|
16
|
+
|
|
17
|
+
export interface AuthSession {
|
|
18
|
+
user: SolidUserProfile;
|
|
19
|
+
loginUrl: string;
|
|
20
|
+
authenticator: Authenticator;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AuthenticatorListener {
|
|
24
|
+
onSessionStarted?: (session: AuthSession) => Promise<void> | void;
|
|
25
|
+
onSessionFailed?: (loginUrl: string, error: ErrorSource) => Promise<void> | void;
|
|
26
|
+
onSessionEnded?: () => Promise<void> | void;
|
|
27
|
+
onAuthenticatedFetchReady?: (fetch: Fetch) => Promise<void> | void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default abstract class Authenticator {
|
|
31
|
+
|
|
32
|
+
public name!: AuthenticatorName;
|
|
33
|
+
|
|
34
|
+
protected authenticatedFetch?: Fetch;
|
|
35
|
+
protected booted?: PromisedValue<void>;
|
|
36
|
+
protected listeners: FluentArray<AuthenticatorListener> = arr<AuthenticatorListener>([]);
|
|
37
|
+
protected _engine?: SolidEngine;
|
|
38
|
+
|
|
39
|
+
public abstract login(loginUrl: string, user?: SolidUserProfile | null): Promise<AuthSession>;
|
|
40
|
+
|
|
41
|
+
public abstract logout(): Promise<void>;
|
|
42
|
+
|
|
43
|
+
public get engine(): Engine {
|
|
44
|
+
this._engine = this._engine ?? new SolidEngine(this.requireAuthenticatedFetch());
|
|
45
|
+
|
|
46
|
+
return this._engine;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getAuthenticatedFetch(): Fetch | null {
|
|
50
|
+
return this.authenticatedFetch ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public requireAuthenticatedFetch(): Fetch {
|
|
54
|
+
return this.authenticatedFetch ?? fail('Authenticated fetch is not ready');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public addListener(listener: AuthenticatorListener): () => void {
|
|
58
|
+
if (!this.listeners.includes(listener)) this.listeners.push(listener);
|
|
59
|
+
|
|
60
|
+
return () => {
|
|
61
|
+
this.removeListener(listener);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public removeListener(listener: AuthenticatorListener): void {
|
|
66
|
+
if (!this.listeners.includes(listener)) return;
|
|
67
|
+
|
|
68
|
+
this.listeners.remove(listener);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async boot(): Promise<void> {
|
|
72
|
+
if (this.booted) {
|
|
73
|
+
return this.booted;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.booted = new PromisedValue();
|
|
77
|
+
|
|
78
|
+
await this.restoreSession();
|
|
79
|
+
|
|
80
|
+
this.booted.resolve();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected abstract restoreSession(): Promise<void>;
|
|
84
|
+
|
|
85
|
+
protected async initAuthenticatedFetch(fetch: Fetch): Promise<void> {
|
|
86
|
+
this.authenticatedFetch = fetch;
|
|
87
|
+
|
|
88
|
+
await this.notifyListeners('onAuthenticatedFetchReady', fetch);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected async startSession(sessionData: Omit<AuthSession, 'authenticator'>): Promise<AuthSession> {
|
|
92
|
+
const session: AuthSession = {
|
|
93
|
+
authenticator: this,
|
|
94
|
+
...sessionData,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
await this.notifyListeners('onSessionStarted', session);
|
|
98
|
+
|
|
99
|
+
return session;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
protected async failSession(loginUrl: string, error: ErrorSource): Promise<void> {
|
|
103
|
+
await this.notifyListeners('onSessionFailed', loginUrl, error);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected async endSession(): Promise<void> {
|
|
107
|
+
await this.notifyListeners('onSessionEnded');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected async notifyListeners<Event extends ListenerEvent>(
|
|
111
|
+
event: Event,
|
|
112
|
+
...payload: ListenerEventPayload<Event>
|
|
113
|
+
): Promise<void> {
|
|
114
|
+
await Promise.all(
|
|
115
|
+
this.listeners.toArray().map(async (listener) => {
|
|
116
|
+
const callback = listener[event] as Closure | undefined;
|
|
117
|
+
|
|
118
|
+
await callback?.(...payload);
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { events, fetch, handleIncomingRedirect, login, logout } from '@inrupt/solid-client-authn-browser';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Storage, after, fail } from '@noeldemartin/utils';
|
|
2
|
+
import type { Fetch } from 'soukai-solid';
|
|
3
|
+
import type {
|
|
4
|
+
ILoginInputOptions,
|
|
5
|
+
events,
|
|
6
|
+
handleIncomingRedirect,
|
|
7
|
+
login,
|
|
8
|
+
logout,
|
|
9
|
+
} from '@inrupt/solid-client-authn-browser';
|
|
10
|
+
|
|
11
|
+
import Authenticator from '@/auth/Authenticator';
|
|
12
|
+
import AuthenticationFailedError from '@/errors/AuthenticationFailedError';
|
|
13
|
+
import type { AuthSession } from '@/auth/Authenticator';
|
|
14
|
+
|
|
15
|
+
import AerogelSolid from 'virtual:aerogel-solid';
|
|
16
|
+
|
|
17
|
+
const STORAGE_KEY = 'inrupt-authenticator';
|
|
18
|
+
|
|
19
|
+
export default class InruptAuthenticator extends Authenticator {
|
|
20
|
+
|
|
21
|
+
private _events!: typeof events;
|
|
22
|
+
private _fetch!: Fetch;
|
|
23
|
+
private _login!: typeof login;
|
|
24
|
+
private _logout!: typeof logout;
|
|
25
|
+
private _handleIncomingRedirect!: typeof handleIncomingRedirect;
|
|
26
|
+
|
|
27
|
+
public async login(loginUrl: string): Promise<AuthSession> {
|
|
28
|
+
Storage.set<string>(STORAGE_KEY, loginUrl);
|
|
29
|
+
|
|
30
|
+
const options: ILoginInputOptions = {
|
|
31
|
+
oidcIssuer: loginUrl,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (AerogelSolid.clientID) {
|
|
35
|
+
options.clientId = AerogelSolid.clientID.client_id;
|
|
36
|
+
options.clientName = AerogelSolid.clientID.client_name;
|
|
37
|
+
options.redirectUrl = AerogelSolid.clientID.redirect_uris[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await this._login(options);
|
|
41
|
+
|
|
42
|
+
// Browser should redirect, so just make it wait for a while.
|
|
43
|
+
await after({ seconds: 60 });
|
|
44
|
+
|
|
45
|
+
return fail('Browser should have redirected, but it didn\'t');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async logout(): Promise<void> {
|
|
49
|
+
await this._logout();
|
|
50
|
+
await this.endSession();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected async restoreSession(): Promise<void> {
|
|
54
|
+
const { events, fetch, handleIncomingRedirect, login, logout } = await import('./InruptAuthenticator.lazy');
|
|
55
|
+
|
|
56
|
+
this._fetch = fetch;
|
|
57
|
+
this._login = login;
|
|
58
|
+
this._logout = logout;
|
|
59
|
+
this._events = events;
|
|
60
|
+
this._handleIncomingRedirect = handleIncomingRedirect;
|
|
61
|
+
|
|
62
|
+
await this.loginFromRedirect();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected async loginFromRedirect(): Promise<void> {
|
|
66
|
+
const loginUrl = Storage.get<string>(STORAGE_KEY);
|
|
67
|
+
if (!loginUrl) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this._events().on('error', (error: string | null, errorDescription?: string | Error | null) => {
|
|
72
|
+
error ??= 'Error using Inrupt Authenticator method';
|
|
73
|
+
|
|
74
|
+
if (typeof errorDescription === 'object') {
|
|
75
|
+
this.failSession(loginUrl, new AuthenticationFailedError(error, null, { cause: errorDescription }));
|
|
76
|
+
} else {
|
|
77
|
+
this.failSession(loginUrl, new AuthenticationFailedError(error, errorDescription));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const session = await this._handleIncomingRedirect(globalThis.location.href);
|
|
82
|
+
|
|
83
|
+
Storage.remove(STORAGE_KEY);
|
|
84
|
+
|
|
85
|
+
if (session?.isLoggedIn && session.webId) {
|
|
86
|
+
await this.initSession(session.webId);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected async initSession(webId: string): Promise<void> {
|
|
91
|
+
await this.initAuthenticatedFetch(this._fetch);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const { default: Solid } = await import('@/services/Solid');
|
|
95
|
+
const user = await Solid.requireUserProfile(webId);
|
|
96
|
+
|
|
97
|
+
await this.startSession({ user, loginUrl: webId });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
await this.failSession(webId, error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import InruptAuthenticator from './authenticators/InruptAuthenticator';
|
|
2
|
+
import type Authenticator from './Authenticator';
|
|
3
|
+
|
|
4
|
+
const _authenticators = {} as Authenticators;
|
|
5
|
+
|
|
6
|
+
type BaseAuthenticators = typeof authenticators;
|
|
7
|
+
|
|
8
|
+
export * from './Authenticator';
|
|
9
|
+
export { default as Authenticator } from './Authenticator';
|
|
10
|
+
|
|
11
|
+
export const authenticators = {
|
|
12
|
+
inrupt: new InruptAuthenticator(),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function setDefaultAuthenticator(authenticator: Authenticator): void {
|
|
16
|
+
_authenticators.default = authenticator;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getAuthenticator<T extends AuthenticatorName>(name: T): Authenticators[T] {
|
|
20
|
+
return _authenticators[name];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function registerAuthenticators(customAuthenticators: Record<string, Authenticator>): void {
|
|
24
|
+
Object.entries(customAuthenticators).forEach(([name, authenticator]) =>
|
|
25
|
+
registerAuthenticator(name as AuthenticatorName, authenticator));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerAuthenticator<T extends AuthenticatorName>(name: T, authenticator: Authenticators[T]): void {
|
|
29
|
+
_authenticators[name] = authenticator;
|
|
30
|
+
|
|
31
|
+
authenticator.name = authenticator.name ?? name;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type AuthenticatorName = keyof Authenticators;
|
|
35
|
+
|
|
36
|
+
export interface Authenticators extends BaseAuthenticators {
|
|
37
|
+
default: Authenticator;
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<img :src="sourceUrl">
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { Cache, computedAsync, requiredStringProp } from '@aerogel/core';
|
|
7
|
+
|
|
8
|
+
import Solid from '@/services/Solid';
|
|
9
|
+
|
|
10
|
+
const props = defineProps({ src: requiredStringProp() });
|
|
11
|
+
const sourceUrl = computedAsync(async () => {
|
|
12
|
+
const cachedResponse = (await Cache.get(props.src)) ?? (await downloadImage(props.src));
|
|
13
|
+
const blob = await cachedResponse?.blob();
|
|
14
|
+
|
|
15
|
+
return blob && URL.createObjectURL(blob);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
async function downloadImage(url: string) {
|
|
19
|
+
try {
|
|
20
|
+
const response = await Solid.fetch(url);
|
|
21
|
+
|
|
22
|
+
if (response.status !== 200) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await Cache.store(url, response);
|
|
27
|
+
|
|
28
|
+
return Cache.get(url);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<slot v-if="$solid.loginStale" name="login-stale">
|
|
4
|
+
<AGMarkdown :text="$td('solid.loginStale', 'This is taking too long...')" />
|
|
5
|
+
</slot>
|
|
6
|
+
|
|
7
|
+
<slot v-if="$solid.loginOngoing" name="login-ongoing">
|
|
8
|
+
<AGMarkdown :text="$td('ui.loading', 'Loading...')" />
|
|
9
|
+
</slot>
|
|
10
|
+
|
|
11
|
+
<slot v-else-if="$solid.isLoggedIn()" name="logged-in" :session="$solid.session">
|
|
12
|
+
<div class="flex flex-col gap-3">
|
|
13
|
+
<AGMarkdown
|
|
14
|
+
:text="
|
|
15
|
+
$td('solid.loggedIn', 'You are logged in as [{userName}]({userWebId})', {
|
|
16
|
+
userName: $solid.user.name ?? $solid.user.webId,
|
|
17
|
+
userWebId: $solid.user.webId,
|
|
18
|
+
})
|
|
19
|
+
"
|
|
20
|
+
/>
|
|
21
|
+
<AGButton @click="$solid.logout()">
|
|
22
|
+
{{ $td('solid.logout', 'Logout') }}
|
|
23
|
+
</AGButton>
|
|
24
|
+
</div>
|
|
25
|
+
</slot>
|
|
26
|
+
|
|
27
|
+
<slot v-else name="logged-out">
|
|
28
|
+
<div class="flex flex-col">
|
|
29
|
+
<AGForm :form="form" class="flex" @submit="$solid.login(form.url)">
|
|
30
|
+
<AGInput
|
|
31
|
+
name="url"
|
|
32
|
+
:aria-label="$td('solid.url', 'Login url')"
|
|
33
|
+
:placeholder="$td('solid.placeholder', 'https://...')"
|
|
34
|
+
/>
|
|
35
|
+
<AGButton submit>
|
|
36
|
+
{{ $td('solid.login', 'Login') }}
|
|
37
|
+
</AGButton>
|
|
38
|
+
</AGForm>
|
|
39
|
+
<AGButton v-if="$solid.wasLoggedIn()" class="mt-3" @click="$solid.reconnect({ force: true })">
|
|
40
|
+
{{ $td('solid.reconnect', 'Reconnect') }}
|
|
41
|
+
</AGButton>
|
|
42
|
+
<p
|
|
43
|
+
v-if="$solid.previousSession?.error || $solid.loginStartupError"
|
|
44
|
+
class="mt-1 self-center text-sm text-red-800"
|
|
45
|
+
>
|
|
46
|
+
<AGMarkdown :text="$td('solid.previousLoginError', 'Previous login attempt failed')" inline />
|
|
47
|
+
<AGLink @click="$errors.inspect($solid.previousSession?.error || $solid.loginStartupError)">
|
|
48
|
+
({{ $td('errors.viewDetails', 'View details') }})
|
|
49
|
+
</AGLink>
|
|
50
|
+
</p>
|
|
51
|
+
</div>
|
|
52
|
+
</slot>
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
55
|
+
|
|
56
|
+
<script setup lang="ts">
|
|
57
|
+
import { AGButton, AGForm, AGInput, AGLink, AGMarkdown, requiredStringInput, useForm } from '@aerogel/core';
|
|
58
|
+
|
|
59
|
+
const form = useForm({ url: requiredStringInput() });
|
|
60
|
+
</script>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative flex items-center justify-center rounded-full bg-gray-200">
|
|
3
|
+
<AGSolidImage
|
|
4
|
+
v-if="$solid.user?.avatarUrl"
|
|
5
|
+
:src="$solid.user?.avatarUrl"
|
|
6
|
+
alt=""
|
|
7
|
+
class="absolute inset-0 h-full w-full rounded-full"
|
|
8
|
+
/>
|
|
9
|
+
<span v-else-if="userInitials" class="text-sm font-semibold tracking-wider text-gray-500" aria-hidden="true">
|
|
10
|
+
{{ userInitials }}
|
|
11
|
+
</span>
|
|
12
|
+
<IconAnonymous v-else class="h-6 w-6 text-gray-500" />
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import IconAnonymous from '~icons/ooui/user-anonymous';
|
|
18
|
+
|
|
19
|
+
import { computed } from 'vue';
|
|
20
|
+
|
|
21
|
+
import Solid from '@/services/Solid';
|
|
22
|
+
|
|
23
|
+
import AGSolidImage from './AGSolidImage.vue';
|
|
24
|
+
|
|
25
|
+
const userInitials = computed(() => {
|
|
26
|
+
const name = Solid.user?.name ?? '';
|
|
27
|
+
|
|
28
|
+
return name
|
|
29
|
+
.trim()
|
|
30
|
+
.split(' ')
|
|
31
|
+
.map((part) => part[0]?.toUpperCase())
|
|
32
|
+
.join('')
|
|
33
|
+
.slice(0, 3);
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import AGSolidImage from './AGSolidImage.vue';
|
|
2
|
+
import AGSolidStatus from './AGSolidStatus.vue';
|
|
3
|
+
import AGSolidUserAvatar from './AGSolidUserAvatar.vue';
|
|
4
|
+
import { IAGSolidStatusLoggedInSlotProps } from './AGSolidStatus';
|
|
5
|
+
|
|
6
|
+
export { AGSolidImage, AGSolidStatus, AGSolidUserAvatar, IAGSolidStatusLoggedInSlotProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { JSError } from '@noeldemartin/utils';
|
|
2
|
+
import type { JSErrorOptions } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
function getErrorMessage(message: string, description?: string | null): string {
|
|
5
|
+
if (!description) {
|
|
6
|
+
return message;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return `${message} (${description})`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class AuthenticationFailedError extends JSError {
|
|
13
|
+
|
|
14
|
+
public readonly description?: string | null;
|
|
15
|
+
|
|
16
|
+
constructor(message: string, description?: string | null, options?: JSErrorOptions) {
|
|
17
|
+
super(getErrorMessage(message), options);
|
|
18
|
+
|
|
19
|
+
this.description = description;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JSError } from '@noeldemartin/utils';
|
|
2
|
+
import type { JSErrorOptions } from '@noeldemartin/utils';
|
|
3
|
+
import type { SolidContainer } from 'soukai-solid';
|
|
4
|
+
|
|
5
|
+
export default class ContainerAlreadyInUse extends JSError {
|
|
6
|
+
|
|
7
|
+
constructor(container: SolidContainer, options?: JSErrorOptions) {
|
|
8
|
+
super(`Container at ${container.url} is already in use`, options);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
}
|