Skip to content

Commit b3f63f9

Browse files
committed
feat(auth-services): add API key support when gating is enabled:
```ts await client.authService.mintWithAuth({ authData, authServiceBaseUrl, scopes, apiKey: 'YOUR_API_KEY', }); ``` ```ts await WebAuthnAuthenticator.registerAndMintPKP({ authServiceBaseUrl, scopes, apiKey: 'YOUR_API_KEY', }); ``` Upcoming PR to use .overrides authBaseUrl and API key instead.
1 parent f131df3 commit b3f63f9

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

packages/auth-services/src/auth-server/server.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/auth-services/src/login-server/app.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import express, { Express } from 'express';
22
import cors from 'cors';
33
import helmet from 'helmet';
4+
// import path from 'node:path';
45
import { logger, requestLogger } from '../auth-server/src/providers/logger';
56

67
export const createLoginApp = (origin: string): Express => {
@@ -9,7 +10,14 @@ export const createLoginApp = (origin: string): Express => {
910
app.use(cors({ origin: true, credentials: true }));
1011
app.use(requestLogger);
1112

12-
// No static UI; consumer should handle any front-end routing/UI.
13+
// app.use(
14+
// express.static(
15+
// path.join(process.cwd(), 'packages/auth-services/src/login-server/public')
16+
// )
17+
// );
18+
19+
// app.get('/', (_req, res) => res.redirect('/index.html'));
20+
// app.get('/error', (_req, res) => res.redirect('/error.html'));
1321

1422
// The OAuth flows remain functionally the same, mapped into Express
1523
// (You can migrate the Google/Discord handlers here 1:1 from Elysia logic.)

packages/auth/src/lib/authenticators/native/WebAuthnAuthenticator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const handleAuthServerRequest = async <T>(params: {
5656
path: '/pkp/mint';
5757
body: any;
5858
jobName: string;
59+
headers?: Record<string, string>;
5960
}): Promise<AuthServerTx<T>> => {
6061
const _body = JSON.stringify(params.body);
6162
const _url = `${params.serverUrl}${params.path}`;
@@ -64,6 +65,7 @@ const handleAuthServerRequest = async <T>(params: {
6465
method: 'POST',
6566
headers: {
6667
'Content-Type': 'application/json',
68+
...(params.headers || {}),
6769
},
6870
body: _body,
6971
});
@@ -149,6 +151,8 @@ export class WebAuthnAuthenticator {
149151
public static async registerAndMintPKP(params: {
150152
username?: string;
151153
authServiceBaseUrl: string;
154+
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
155+
apiKey?: string;
152156
}): Promise<{
153157
pkpInfo: PKPData;
154158

@@ -191,6 +195,7 @@ export class WebAuthnAuthenticator {
191195
serverUrl: params.authServiceBaseUrl,
192196
path: '/pkp/mint',
193197
body: authData,
198+
headers: params.apiKey ? { 'x-api-key': params.apiKey } : undefined,
194199
});
195200

196201
return {

packages/networks/src/networks/shared/helpers/handleAuthServerRequest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const handleAuthServerRequest = async <T>(params: {
66
path: '/pkp/mint';
77
body: any;
88
jobName: string;
9+
headers?: Record<string, string>;
910
}): Promise<AuthServerTx<T>> => {
1011
const _body = JSON.stringify(params.body);
1112
const _url = `${params.serverUrl}${params.path}`;
@@ -14,6 +15,7 @@ export const handleAuthServerRequest = async <T>(params: {
1415
method: 'POST',
1516
headers: {
1617
'Content-Type': 'application/json',
18+
...(params.headers || {}),
1719
},
1820
body: _body,
1921
});

packages/networks/src/networks/vNaga/shared/factories/BaseModuleFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ export function createBaseModule<T, M>(config: BaseModuleConfig<T, M>) {
421421
authData: AuthData;
422422
authServiceBaseUrl?: string;
423423
scopes?: ('sign-anything' | 'personal-sign' | 'no-permissions')[];
424+
apiKey?: string;
424425
}) => {
425426
return await handleAuthServerRequest<PKPData>({
426427
jobName: 'PKP Minting',
@@ -434,6 +435,7 @@ export function createBaseModule<T, M>(config: BaseModuleConfig<T, M>) {
434435
pubkey: params.authData.publicKey,
435436
scopes: params.scopes,
436437
},
438+
headers: params.apiKey ? { 'x-api-key': params.apiKey } : undefined,
437439
});
438440
},
439441
},

0 commit comments

Comments
 (0)