Skip to content

Commit cc78c05

Browse files
committed
✨ add /oauth2/token to retrieve refresh token via HTTP
1 parent 80f4446 commit cc78c05

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ export function start(
150150
controller.oAuth2Callback(req, res),
151151
);
152152

153+
app.get('/oauth2/token', (req, res) => controller.oAuth2Token(req, res));
154+
153155
app.get('/account/id', (req, res, next) =>
154156
controller.getAccountId(req, res, next),
155157
);

src/models/controller.model.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,27 @@ export class Controller {
13291329
}
13301330
}
13311331

1332+
public async oAuth2Token(req: Request, res: Response): Promise<string> {
1333+
try {
1334+
if (!this.adapter.handleOAuth2Callback) {
1335+
throw new ServerError(501, 'OAuth2 flow not implemented');
1336+
}
1337+
1338+
const { apiKey } = await this.adapter.handleOAuth2Callback(req, res);
1339+
1340+
return apiKey;
1341+
} catch (error) {
1342+
errorLogger(
1343+
'oAuth2Callback',
1344+
'Unable to save OAuth2 token:',
1345+
'',
1346+
error || 'Unknown',
1347+
);
1348+
1349+
throw error;
1350+
}
1351+
}
1352+
13321353
public async getAccountId(
13331354
req: BridgeRequest<unknown>,
13341355
res: Response,

0 commit comments

Comments
 (0)