mirror of
https://github.com/outline/outline.git
synced 2026-12-04 10:24:43 +03:00
refactor: add OAuthClient.findByClientId
This commit is contained in:
1 parent
7fc305b5d5
commit
98959dc330
3 files changed
+18
-9
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user