Skip to content

Logout using OIDC credentials instead of cookies #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flow-typed/lib-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ declare module '@solid/oidc-rp' {
createRequest(options: Object, storage: Object): Promise<string>,
serialize(): string,
validateResponse(response: string, session: Object): Promise<Object>,
logout(): Promise<void>
logoutRequest(options?: Object): Promise<void>
}
}
7 changes: 3 additions & 4 deletions src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { getData, updateStorage } from './storage'
export type webIdOidcSession = {
idp: string,
webId: string,
accessToken: string,
idToken: string,
clientId: string,
sessionKey: string
authorization: {
id_token: string
}
}

export type Session = webIdOidcSession
Expand Down
2 changes: 1 addition & 1 deletion src/solid-auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class SolidAuthClient extends EventEmitter {
const session = await getSession(storage)
if (session) {
try {
await WebIdOidc.logout(storage)
await WebIdOidc.logout(storage, globalFetch)
this.emit('logout')
this.emit('session', null)
} catch (err) {
Expand Down
14 changes: 11 additions & 3 deletions src/webid-oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PoPToken from '@solid/oidc-rp/lib/PoPToken'
import type { loginOptions } from './solid-auth-client'
import { currentUrl, navigateTo, toUrlString } from './url-util'
import type { webIdOidcSession } from './session'
import { getSession } from './session'
import type { AsyncStorage } from './storage'
import { defaultStorage, getData, updateStorage } from './storage'

Expand Down Expand Up @@ -55,11 +56,18 @@ export async function currentSession(
}
}

export async function logout(storage: AsyncStorage): Promise<void> {
export async function logout(
storage: AsyncStorage,
fetch: Function
): Promise<void> {
const rp = await getStoredRp(storage)
if (rp) {
const session = await getSession(storage)
if (rp && session) {
try {
rp.logout()
const url = rp.logoutRequest({
id_token_hint: session.authorization.id_token
})
await fetch(url, { method: 'POST' })
} catch (err) {
console.warn('Error logging out of the WebID-OIDC session')
console.error(err)
Expand Down