refactor: add OAuthClient.findByClientId

This commit is contained in:
Tom Moor committed 2025-04-08 09:16:55 -04:00
1 parent 7fc305b5d5
commit 98959dc330
3 files changed
+18 -9

No files matched your search

+16
View File
@@ -125,6 +125,22 @@ class OAuthClient extends ParanoidModel<
model.clientSecret = OAuthClient.generateNewClientSecret();
}
// static methods
/**
* Find an OAuthClient by it's public `clientId`
*
* @param clientId The public clientId of the OAuthClient
* @returns The OAuthClient or null if not found
*/
public static async findByClientId(clientId: string) {
return this.findOne({
where: {
clientId,
},
});
}
private static generateNewClientId(): string {
return rs.generate({
length: 20,
+1 -4
View File
@@ -29,10 +29,7 @@ router.post(
throw ValidationError("Missing client_id");
}
const client = await OAuthClient.findOne({
where: { clientId },
rejectOnEmpty: true,
});
const client = await OAuthClient.findByClientId(clientId);
authorize(user, "read", client);
// Note: These objects are mutated by the OAuth2Server library
+1 -5
View File
@@ -121,11 +121,7 @@ export const OAuthInterface: RefreshTokenModel &
},
async getClient(clientId: string, clientSecret?: string) {
const client = await OAuthClient.findOne({
where: {
clientId,
},
});
const client = await OAuthClient.findByClientId(clientId);
if (!client) {
return false;
}