mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Simplify and merge OIDC configurations
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
import type { CanBePromise, interactionPolicy, KoaContextWithOIDC } from 'oidc-provider';
|
||||
|
||||
/**
|
||||
* Config options to communicate exactly how to handle requests.
|
||||
*/
|
||||
export interface InteractionPolicy {
|
||||
policy: interactionPolicy.Prompt[];
|
||||
url: (ctx: KoaContextWithOIDC) => CanBePromise<string>;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import type { KoaContextWithOIDC } from 'oidc-provider';
|
||||
import { interactionPolicy } from 'oidc-provider';
|
||||
import { ensureTrailingSlash } from '../../../util/PathUtil';
|
||||
import type {
|
||||
InteractionPolicy,
|
||||
} from '../InteractionPolicy';
|
||||
|
||||
/**
|
||||
* Interaction policy that redirects to `idpPath`.
|
||||
* Uses the `select_account` interaction policy.
|
||||
*/
|
||||
export class AccountInteractionPolicy implements InteractionPolicy {
|
||||
public readonly policy: interactionPolicy.Prompt[];
|
||||
public readonly url: (ctx: KoaContextWithOIDC) => string;
|
||||
|
||||
public constructor(idpPath: string) {
|
||||
if (!idpPath.startsWith('/')) {
|
||||
throw new Error('idpPath needs to start with a /');
|
||||
}
|
||||
const interactions = interactionPolicy.base();
|
||||
const selectAccount = new interactionPolicy.Prompt({
|
||||
name: 'select_account',
|
||||
requestable: true,
|
||||
});
|
||||
interactions.add(selectAccount, 0);
|
||||
this.policy = interactions;
|
||||
|
||||
// When oidc-provider cannot fulfill the authorization request for any of the possible reasons
|
||||
// (missing user session, requested ACR not fulfilled, prompt requested, ...)
|
||||
// it will resolve the interactions.url helper function and redirect the User-Agent to that url.
|
||||
this.url = (): string => ensureTrailingSlash(idpPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user