Skip to content

Commit

Permalink
feat: drop SIWE params from sign in URLs (#206)
Browse files Browse the repository at this point in the history
## Motivation

Shorten SIWF deep links/QR codes.

## Change Summary

Remove SIWE params from URLs.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [x] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [x] PR has a changeset
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [ ] PR includes documentation if necessary
- [x] All commits have been signed
  • Loading branch information
horsefacts committed Aug 21, 2024
1 parent 59b7725 commit 088f6ca
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 45 deletions.
7 changes: 7 additions & 0 deletions .changeset/tidy-badgers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@farcaster/auth-client": minor
"@farcaster/auth-relay": minor
"@farcaster/auth-kit": minor
---

Drop SIWE params from sign in URLs
3 changes: 1 addition & 2 deletions apps/relay/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export const REDIS_URL = process.env["REDIS_URL"] || "redis://localhost:6379";
export const RELAY_SERVER_PORT = Number(process.env["RELAY_SERVER_PORT"] || "8000");
export const RELAY_SERVER_HOST = process.env["RELAY_SERVER_HOST"] || "localhost";

export const URL_BASE =
process.env["URL_BASE"] || process.env["CONNECT_URI_BASE"] || "https://warpcast.com/~/sign-in-with-farcaster";
export const URL_BASE = process.env["URL_BASE"] || process.env["CONNECT_URI_BASE"] || "https://warpcast.com/~/siwf";

export const HUB_URL = process.env["HUB_URL"] || "https://hoyt.farcaster.xyz:2281";
export const HUB_FALLBACK_URL = process.env["HUB_FALLBACK_URL"] || "https://lamia.farcaster.xyz:2281";
Expand Down
2 changes: 1 addition & 1 deletion apps/relay/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("relay server", () => {
expect(response.status).toBe(201);
const { channelToken, url, connectUri, nonce, ...rest } = response.data;
expect(channelToken).toMatch(/[2-9A-HJ-NP-Z]{8}/);
expect(url).toMatch("https://warpcast.com/~/sign-in-with-farcaster");
expect(url).toMatch("https://warpcast.com/~/siwf");
expect(url).toBe(connectUri);
expect(rest).toStrictEqual({});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-client/src/actions/app/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("status", () => {
const statusResponseDataStub: StatusAPIResponse = {
state: "pending",
nonce: "abcd1234",
url: "https://warpcast.com/~/sign-in-with-farcaster?nonce=abcd1234[...]",
url: "https://warpcast.com/~/siwf?channelToken=ABCD2345",
signatureParams: {
domain: "example.com",
siweUri: "https://example.com/login",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-client/src/actions/auth/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("authenticate", () => {
const statusResponseDataStub: AuthenticateAPIResponse = {
state: "completed",
nonce: "abcd1234",
url: "https://warpcast.com/~/siwf?channelToken=ABCD2345",
signatureParams: {
nonce: "abcd1234",
siweUri: "https://example.com/login",
Expand All @@ -33,7 +34,6 @@ describe("authenticate", () => {
ip: "127.0.0.1",
userAgent: "Mozilla/5.0",
},
url: "https://warpcast.com/~/sign-in-with-farcaster?nonce=abcd1234[...]",
message,
signature,
fid,
Expand Down
11 changes: 3 additions & 8 deletions packages/auth-client/src/actions/auth/parseSignInURI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ describe("parseSignInURI", () => {
});

test("parses sign in params from protocol URI", async () => {
const { channelToken, params } = client.parseSignInURI({
uri: "https://warpcast.com/~/sign-in-with-farcaster?channelToken=76be6229-bdf7-4ad2-930a-540fb2de1e08&nonce=ESsxs6MaFio7OvqWb&siweUri=https%3A%2F%2Fexample.com%2Flogin&domain=example.com",
const { channelToken } = client.parseSignInURI({
uri: "https://warpcast.com/~/siwf?channelToken=ABCD2345",
});

expect(channelToken).toBe("76be6229-bdf7-4ad2-930a-540fb2de1e08");
expect(params).toStrictEqual({
domain: "example.com",
uri: "https://example.com/login",
nonce: "ESsxs6MaFio7OvqWb",
});
expect(channelToken).toBe("ABCD2345");
});
});
5 changes: 0 additions & 5 deletions packages/auth-client/src/messages/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SiweMessage } from "siwe";
import { err, ok } from "neverthrow";
import { AuthClientResult } from "../errors";
import { validate } from "./validate";
import { parseSignInURI } from "./parseSignInURI";
import { STATEMENT, CHAIN_ID } from "./constants";

export type FarcasterResourceParams = {
Expand All @@ -29,10 +28,6 @@ export const build = (params: SignInMessageParams): AuthClientResult<BuildRespon
}
};

export const buildFromSignInURI = (signInUri: string, fid: number): AuthClientResult<BuildResponse> => {
return parseSignInURI(signInUri).andThen(({ params }) => build({ ...params, fid }));
};

const buildFidResource = (fid: number): string => {
return `farcaster://fid/${fid}`;
};
11 changes: 2 additions & 9 deletions packages/auth-client/src/messages/parseSignInURI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import { parseSignInURI } from "./parseSignInURI";

describe("parseSignInUri", () => {
test("parses Sign in With Farcaster URI into message params", () => {
const signInUri =
"https://warpcast.com/~/sign-in-with-farcaster?channelToken=76be6229-bdf7-4ad2-930a-540fb2de1e08&nonce=ESsxs6MaFio7OvqWb&siweUri=https%3A%2F%2Fexample.com%2Flogin&domain=example.com&redirectUrl=https%3A%2F%2Fexample.com";
const signInUri = "https://warpcast.com/~/siwf?channelToken=ABCD2345";
const result = parseSignInURI(signInUri);
expect(result._unsafeUnwrap()).toStrictEqual({
channelToken: "76be6229-bdf7-4ad2-930a-540fb2de1e08",
params: {
domain: "example.com",
uri: "https://example.com/login",
nonce: "ESsxs6MaFio7OvqWb",
redirectUrl: "https://example.com",
},
channelToken: "ABCD2345",
});
});
});
20 changes: 2 additions & 18 deletions packages/auth-client/src/messages/parseSignInURI.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import { err, ok } from "neverthrow";
import { AuthClientError, AuthClientResult } from "../errors";
import { SignInMessageParams } from "./build";

export interface ParsedSignInURI {
channelToken: string;
params?: Partial<SignInMessageParams> & { redirectUrl?: string };
}

export const parseSignInURI = (signInUri: string): AuthClientResult<ParsedSignInURI> => {
const url = new URL(signInUri);
const searchParams = Object.fromEntries(url.searchParams.entries());
const { channelToken, ...params } = searchParams;
const { channelToken } = searchParams;
if (!channelToken) {
return err(validationFail("No channel token provided"));
}
if (params["nonce"] || params["siweUri"] || params["domain"]) {
if (!params["nonce"]) {
return err(validationFail("No nonce provided"));
}
if (!params["siweUri"]) {
return err(validationFail("No SIWE URI provided"));
}
if (!params["domain"]) {
return err(validationFail("No domain provided"));
}
const { siweUri, ...siweParams } = params;
return ok({ channelToken, params: { uri: siweUri, ...siweParams } });
} else {
return ok({ channelToken });
}
return ok({ channelToken });
};

const validationFail = (message: string): AuthClientError => {
Expand Down

0 comments on commit 088f6ca

Please sign in to comment.