| 54 | } |
| 55 | |
| 56 | registerClient( |
| 57 | client: Omit<OAuthClientInformationFull, "client_id" | "client_id_issued_at">, |
| 58 | allowedRedirectHosts: string[], |
| 59 | ): OAuthClientInformationFull { |
| 60 | if (!client.redirect_uris.every((uri) => redirectHostAllowed(String(uri), allowedRedirectHosts))) { |
| 61 | throw new InvalidRequestError("Client redirect_uri is not allowed for this DevSpace server"); |
| 62 | } |
| 63 | |
| 64 | const now = Math.floor(Date.now() / 1000); |
| 65 | const registered: OAuthClientInformationFull = { |
| 66 | ...client, |
| 67 | client_id: `devspace-${randomUUID()}`, |
| 68 | client_id_issued_at: now, |
| 69 | token_endpoint_auth_method: client.token_endpoint_auth_method ?? "none", |
| 70 | grant_types: client.grant_types ?? ["authorization_code", "refresh_token"], |
| 71 | response_types: client.response_types ?? ["code"], |
| 72 | }; |
| 73 | |
| 74 | this.database.sqlite |
| 75 | .prepare("insert into oauth_clients (client_id, client_json, issued_at) values (?, ?, ?)") |
| 76 | .run(registered.client_id, JSON.stringify(registered), now); |
| 77 | |
| 78 | return registered; |
| 79 | } |
| 80 | |
| 81 | saveAccessToken(tokenHash: string, record: PersistedAccessTokenRecord): void { |
| 82 | this.database.sqlite |