Skip to content

Commit

Permalink
feat: add app owner details
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Sep 3, 2024
1 parent 3e0cd76 commit 9f4c940
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions migrations/create-tables.js.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CREATE TABLE `gp_apps` (
`user_updated` char(36) DEFAULT NULL,
`date_updated` timestamp NULL DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`owner_name` varchar(255) NULL DEFAULT NULL,
`owner_url` varchar(255) NULL DEFAULT NULL,
`secret` varchar(255) DEFAULT NULL,
`redirect_urls` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin CHECK (json_valid(`redirect_urls`)),
`grants` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '\'[]\'' CHECK (json_valid(`grants`)),
Expand Down
2 changes: 2 additions & 0 deletions seeds/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const apps = [
id: 'b2a50a7e-6dc5-423d-864e-173ea690992e',
user_created: users[1]!.id,
name: 'App Two',
owner_name: 'Some Organization',
owner_url: 'https://example.com/org',
secret: 'secret2',
redirect_urls: JSON.stringify([ 'https://example.com/two/callback' ]),
grants: JSON.stringify([ 'authorization_code', 'refresh_token' ]),
Expand Down
4 changes: 3 additions & 1 deletion src/oauth/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class OAuthModel implements AuthorizationCodeModel, RefreshTokenM
await Promise.all([
this.redis.json.set(key, '$', {
...code,
client: { id: client.id, name: client.name },
client: { id: client.id, name: client.name, owner: { name: client.owner_name, url: client.owner_url } },
user: { id: user.id, $state: user.$state },
}),
this.redis.pExpireAt(key, code.expiresAt),
Expand Down Expand Up @@ -216,6 +216,8 @@ export default class OAuthModel implements AuthorizationCodeModel, RefreshTokenM
id: client.id,
name: client.name,
secret: client.secret,
owner_name: client.owner_name,
owner_url: client.owner_url,
requestSecret: clientSecret,
redirectUris: JSON.parse(client.redirect_urls) as string[],
grants: JSON.parse(client.grants) as string[],
Expand Down
6 changes: 4 additions & 2 deletions src/oauth/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AuthorizationCode, Client, Token as TokenWithClientUser } from '@node-oauth/oauth2-server';

export type AuthorizationCodeToSave = Pick<AuthorizationCode, 'authorizationCode' | 'expiresAt' | 'redirectUri' | 'scope' | 'codeChallenge' | 'codeChallengeMethod'>;
export type AuthorizationCodeSaved = AuthorizationCodeToSave & { client: Pick<Client, 'id' | 'name'>, user: User };
export type AuthorizationCodeSaved = AuthorizationCodeToSave & { client: Pick<Client, 'id' | 'name'>, user: User, owner: { name: string | null, url: string | null } };
export type PublicAuthorizationCodeDetails = Pick<AuthorizationCodeSaved, 'scope' | 'client'>;
export type Token = Pick<TokenWithClientUser, 'accessToken' | 'accessTokenExpiresAt' | 'refreshToken' | 'refreshTokenExpiresAt' | 'scope'>;
export type ClientWithCredentials = Client & { name: string, secret: string | null };
export type ClientWithCredentials = Client & { name: string, secret: string | null, owner_name: string | null, owner_url: string | null };
export type User = { id: string; $state: string | null };

export type InternalToken = {
Expand All @@ -29,6 +29,8 @@ export type InternalTokenRow = Omit<InternalToken, 'scopes' | 'origins'> & {
export type ClientRow = {
id: string;
name: string;
owner_name: string | null;
owner_url: string | null;
secret: string | null;
redirect_urls: string;
grants: string;
Expand Down

0 comments on commit 9f4c940

Please sign in to comment.