mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Move /api/v1/sso to OpenID plugin
This commit is contained in:
parent
c7ec678a3e
commit
96d1805925
12 changed files with 710 additions and 249 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue