refactor(api): ♻️ Move /api/v1/sso to OpenID plugin

This commit is contained in:
Jesse Wierzbinski 2024-09-24 14:42:39 +02:00
parent c7ec678a3e
commit 96d1805925
No known key found for this signature in database
12 changed files with 710 additions and 249 deletions

View file

@ -408,6 +408,41 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
return this.update(this.data);
}
public async getLinkedOidcAccounts(): Promise<
{
id: string;
name: string;
url: string;
icon?: string | undefined;
server_id: string;
}[]
> {
// Get all linked accounts
const accounts = await db.query.OpenIdAccounts.findMany({
where: (User, { eq }) => eq(User.userId, this.id),
});
return accounts
.map((account) => {
const issuer = config.oidc.providers.find(
(provider) => provider.id === account.issuerId,
);
if (!issuer) {
return null;
}
return {
id: issuer.id,
name: issuer.name,
url: issuer.url,
icon: proxyUrl(issuer.icon) || undefined,
server_id: account.serverId,
};
})
.filter((x) => x !== null);
}
async updateFromRemote(): Promise<User> {
if (!this.isRemote()) {
throw new Error(