Skip to content

Commit cf449bd

Browse files
committed
add legacy token grant type
toobeeh/skribbltypo#449
1 parent f65f2ac commit cf449bd

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

tirith-api/src/modules/auth/controller/oauth2.controller.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ export class OAuth2Controller {
164164
};
165165
}
166166

167+
else if (exchange.grant_type === "typo-legacy-token") {
168+
169+
if(exchange.subject_token === undefined || exchange.client_id === undefined) {
170+
throw new BadRequestException("Missing required parameters: subject_token and client_id are required for typo_legacy_token grant type.");
171+
}
172+
173+
const member = await this.membersService.getByAccessToken(exchange.subject_token);
174+
const client = await this.authService.getOauthClientById(exchange.client_id);
175+
const newToken = await this.authService.createAccessToken(member.typoId, client.clientId, this.openidService.openIdConfig.issuer, client.audience);
176+
177+
return {
178+
access_token: newToken,
179+
token_type: "Bearer",
180+
issued_token_type: "urn:ietf:params:oauth:token-type:jwt",
181+
expires_in: client.tokenExpiry,
182+
scope: client.scopes.join(" ")
183+
};
184+
}
185+
167186
else {
168187
throw new BadRequestException(`Unsupported grant type: ${exchange.grant_type}`);
169188
}

tirith-api/src/modules/auth/dto/oauth2TokenExchangeDto.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import {XApiProperty} from "../../../decorators/apiProperty.decorator";
22

33
export class OAuth2TokenExchangeDto {
44

5-
@XApiProperty({ description: "The oauth2 grant type" })
5+
@XApiProperty({ description: "The oauth2 grant type, supported: authorization_code, token-exchange, typo-legacy-token, " })
66
grant_type: string; // naming acc to oauth spec
77

88
@XApiProperty({ description: "An authorization code received from the OAuth2 client, required for grant_type=code", required: false })
99
code?: string; // naming acc to oauth spec
1010

11-
@XApiProperty({ description: "The client ID of the OAuth2 client, required for grant_type=code", required: false })
11+
@XApiProperty({ description: "The client ID of the OAuth2 client, required for grant_type=code or typo-legacy-token", required: false })
1212
client_id?: number; // naming acc to oauth spec
1313

14-
@XApiProperty({ description: "An access token to be exchanged, required for grant_type=token-exchange", required: false })
14+
@XApiProperty({ description: "An access token to be exchanged, required for grant_type=token-exchange or typo-legacy-token", required: false })
1515
subject_token?: string; // naming acc to oauth spec
1616

1717
@XApiProperty({ description: "The type of the subject token, required for grant_type=token-exchange", required: false })

0 commit comments

Comments
 (0)