Skip to content

Commit fc3319e

Browse files
committed
replace Inrupt by Uvdsl OIDC client
1 parent cbbcca1 commit fc3319e

6 files changed

Lines changed: 85 additions & 17 deletions

File tree

jest.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export default {
1515
],
1616
setupFilesAfterEnv: ['./test/helpers/setup.ts'],
1717
moduleNameMapper: {
18-
'^.+\\.css$': '<rootDir>/__mocks__/styleMock.js'
18+
'^.+\\.css$': '<rootDir>/__mocks__/styleMock.js',
19+
'^solid-logic$': '<rootDir>/../solid-logic/src',
20+
'^@uvdsl/solid-oidc-client-browser$': '<rootDir>/test/mocks/solid-oidc-client-browser.ts'
1921
},
2022
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
2123
roots: ['<rootDir>/src', '<rootDir>/test', '<rootDir>/__mocks__'],

src/login/login.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,7 @@ export function renderSignInPopup (dom: HTMLDocument) {
513513
// Login
514514
const locationUrl = new URL(window.location.href)
515515
locationUrl.hash = '' // remove hash part
516-
await authSession.login({
517-
redirectUrl: locationUrl.href,
518-
oidcIssuer: issuerUri
519-
})
516+
await authSession.login(issuerUri, locationUrl.href)
520517
} catch (err) {
521518
alert(err.message)
522519
}
@@ -669,9 +666,9 @@ export function loginStatusBox (
669666
}
670667

671668
box.refresh = function () {
672-
const sessionInfo = authSession.info
673-
if (sessionInfo && sessionInfo.webId && sessionInfo.isLoggedIn) {
674-
me = solidLogicSingleton.store.sym(sessionInfo.webId)
669+
const webId = authSession.webId
670+
if (webId) {
671+
me = solidLogicSingleton.store.sym(webId)
675672
} else {
676673
me = null
677674
}

src/v2/components/footer/Footer.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ export class Footer extends LitElement {
107107
if (typeof authSession.events.off === 'function') {
108108
authSession.events.off('login', this._updateFooter)
109109
authSession.events.off('logout', this._updateFooter)
110-
} else if (typeof authSession.events.removeListener === 'function') {
111-
authSession.events.removeListener('login', this._updateFooter)
112-
authSession.events.removeListener('logout', this._updateFooter)
113110
}
114111
super.disconnectedCallback()
115112
}

src/v2/components/loginButton/LoginButton.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ export class LoginButton extends LitElement {
377377

378378
const locationUrl = new URL(window.location.href)
379379
locationUrl.hash = ''
380-
await authSession.login({
381-
redirectUrl: locationUrl.href,
382-
oidcIssuer: issuerUri
383-
})
380+
await authSession.login(issuerUri, locationUrl.href)
384381
} catch (err: any) {
385382
this._errorMsg = err.message || String(err)
386383
this.requestUpdate()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
type Listener = (...args: any[]) => void
2+
3+
class EventEmitterLike {
4+
private listeners: Record<string, Listener[]> = {}
5+
6+
on (event: string, listener: Listener): void {
7+
const list = this.listeners[event] || []
8+
list.push(listener)
9+
this.listeners[event] = list
10+
}
11+
12+
off (event: string, listener: Listener): void {
13+
const list = this.listeners[event] || []
14+
this.listeners[event] = list.filter(item => item !== listener)
15+
}
16+
17+
emit (event: string, ...args: any[]): void {
18+
const list = this.listeners[event] || []
19+
list.forEach(listener => listener(...args))
20+
}
21+
}
22+
23+
export class Session {
24+
info: { webId?: string, isLoggedIn: boolean } = { isLoggedIn: false }
25+
webId?: string
26+
isActive = false
27+
events = new EventEmitterLike()
28+
29+
private eventTarget = new EventTarget()
30+
31+
addEventListener (type: string, listener: EventListenerOrEventListenerObject | null): void {
32+
if (!listener) return
33+
this.eventTarget.addEventListener(type, listener)
34+
}
35+
36+
removeEventListener (type: string, listener: EventListenerOrEventListenerObject | null): void {
37+
if (!listener) return
38+
this.eventTarget.removeEventListener(type, listener)
39+
}
40+
41+
dispatchEvent (event: Event): boolean {
42+
return this.eventTarget.dispatchEvent(event)
43+
}
44+
45+
async handleIncomingRedirect (): Promise<void> {
46+
47+
}
48+
49+
async handleRedirectFromLogin (): Promise<void> {
50+
51+
}
52+
53+
async restore (): Promise<void> {
54+
55+
}
56+
57+
async login (_idp?: string, _redirectUri?: string): Promise<void> {
58+
}
59+
60+
async logout (): Promise<void> {
61+
this.info = { isLoggedIn: false }
62+
this.webId = undefined
63+
this.isActive = false
64+
}
65+
66+
fetch (input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
67+
return globalThis.fetch(input, init)
68+
}
69+
70+
authFetch (input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
71+
return globalThis.fetch(input, init)
72+
}
73+
}

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@
6363
"declarations.d.ts"
6464
] /* List of folders to include type definitions from. */,
6565
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
66-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
67-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
66+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
67+
"preserveSymlinks": true, /* Do not resolve the real path of symlinks. Needed for local linked solid-logic. */
68+
"baseUrl": ".", /* Base directory to resolve non-absolute module names. Needed for paths mapping. */
69+
"paths": { "rdflib": ["./node_modules/rdflib"] }, /* Map rdflib to avoid duplicate type identity when linked with solid-logic. */
6870

6971
/* Source Map Options */
7072
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */

0 commit comments

Comments
 (0)