-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathopenidHelper.ts
More file actions
35 lines (31 loc) · 1012 Bytes
/
openidHelper.ts
File metadata and controls
35 lines (31 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as client from "openid-client";
export class OpenIdHelper {
private issuerUrl: URL;
private clientId: string;
constructor(issuerUrl: string, clientId: string) {
if (!issuerUrl || issuerUrl.trim() === "") {
throw new Error("Issuer URL is required");
}
if (!clientId || clientId.trim() === "") {
throw new Error("Client ID is required");
}
this.issuerUrl = new URL(issuerUrl);
this.clientId = clientId;
}
/**
* Discover issuer metadata from the OpenID Connect provider
*/
async discoverIssuer() {
return await client.discovery(this.issuerUrl, this.clientId);
}
/**
* Retrieve the authorization endpoint from the issuer
*/
async getAuthorizationEndpoint(): Promise<string> {
const issuer = await this.discoverIssuer();
if (!issuer.serverMetadata().authorization_endpoint) {
throw new Error("Authorization endpoint not found in issuer metadata");
}
return issuer.serverMetadata().authorization_endpoint!;
}
}