Skip to content

Commit

Permalink
feat: add request metadata to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
horsefacts committed Aug 20, 2024
1 parent e50cb04 commit c63ba11
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/relay/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export type AuthenticateRequest = {
pfpUrl: string;
};

export type SessionMetadata = {
ip: string;
userAgent: string;
};

export type RelaySession = {
state: "pending" | "completed";
nonce: string;
Expand All @@ -38,6 +43,7 @@ export type RelaySession = {
verifications?: string[];
custody?: Hex;
signatureParams: CreateChannelRequest;
metadata: SessionMetadata;
};

const constructUrl = (channelToken: string, nonce: string, extraParams: CreateChannelRequest): string => {
Expand All @@ -59,6 +65,10 @@ export async function createChannel(request: FastifyRequest<{ Body: CreateChanne
url,
connectUri: url,
signatureParams: { ...request.body, nonce },
metadata: {
userAgent: request.headers["user-agent"] ?? "Unknown",
ip: request.ip,
},
});
if (update.isOk()) {
return reply.code(201).send({ channelToken, url, connectUri: url, nonce });
Expand Down
4 changes: 4 additions & 0 deletions apps/relay/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ describe("relay server", () => {
domain: "example.com",
siweUri: "https://example.com",
},
metadata: {
ip: "127.0.0.1",
userAgent: "axios/1.7.4",
},
});
});

Expand Down
2 changes: 1 addition & 1 deletion apps/relay/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface RelayServerConfig {
}

export class RelayServer {
app = fastify({ logger });
app = fastify({ logger, trustProxy: true });
channels: ChannelStore<RelaySession>;
addresses: AddressService;

Expand Down
4 changes: 4 additions & 0 deletions packages/auth-client/src/actions/app/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe("status", () => {
domain: "example.com",
siweUri: "https://example.com/login",
},
metadata: {
ip: "127.0.0.1",
userAgent: "Mozilla/5.0",
},
};

test("constructs API request", async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/auth-client/src/actions/app/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface StatusAPIResponse {
requestId?: string;
redirectUrl?: string;
};
metadata: {
ip: string;
userAgent: string;
};
}

const path = "channel/status";
Expand Down
9 changes: 9 additions & 0 deletions packages/auth-client/src/actions/auth/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe("authenticate", () => {
const statusResponseDataStub: AuthenticateAPIResponse = {
state: "completed",
nonce: "abcd1234",
signatureParams: {
nonce: "abcd1234",
siweUri: "https://example.com/login",
domain: "example.com",
},
metadata: {
ip: "127.0.0.1",
userAgent: "Mozilla/5.0",
},
url: "https://warpcast.com/~/sign-in-with-farcaster?nonce=abcd1234[...]",
message,
signature,
Expand Down

0 comments on commit c63ba11

Please sign in to comment.