Skip to content

Commit fa159c6

Browse files
Merge branch 'docs/feat/browser-sdk'
2 parents a5d997e + a8f16c5 commit fa159c6

25 files changed

+602
-141
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# Custom backend
2+
3+
:::caution
4+
5+
This page is under construction.
6+
7+
:::

docs/docs/concepts/auth0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# Auth0
2+
3+
:::caution
4+
5+
This page is under construction.
6+
7+
:::

docs/docs/concepts/getting-started.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
FastAuth is a NEAR Protocol authentication system that enables secure transaction signing through Multi-Party Computation (MPC) and JWT-based verification.
44

5-
## Key Components
6-
7-
**FastAuth Contract** - Main entry point that manages guards and coordinates MPC signing
8-
9-
**JwtGuardRouter** - Routes JWT verification to appropriate guard contracts
10-
11-
**Auth0Guard** - Verifies Auth0-issued JWT tokens using RS256
12-
135
## Quick Start
146

157
1. Review the [Architecture Overview](./architecture_overview.md)

docs/docs/integrations/auth0.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# Integrate with Auth0
1+
# Auth0
2+
3+
:::caution
4+
5+
This page is under construction.
6+
7+
:::
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Express
2+
3+
# Integrate your custom backend
4+
5+
This guide shows how to build a custom backend that generates JWT tokens for FastAuth transaction signing using Express.js.
6+
7+
## Prerequisites
8+
9+
- Node.js and npm/pnpm installed
10+
- RSA key pair for JWT signing
11+
12+
## Step 1: Generate RSA Key Pair
13+
14+
```bash
15+
# Generate private key
16+
openssl genrsa -out jwtRS256.key 2048
17+
18+
# Generate public key
19+
openssl rsa -in jwtRS256.key -pubout -out jwtRS256.pub
20+
```
21+
22+
## Step 2: Install Dependencies
23+
24+
```bash
25+
npm install express jsonwebtoken
26+
npm install -D @types/express @types/jsonwebtoken @types/node typescript
27+
```
28+
29+
## Step 3: Create the Express Server
30+
31+
```typescript
32+
import { Request, Response } from "express";
33+
import express from "express";
34+
import jwt from "jsonwebtoken";
35+
import * as fs from "node:fs";
36+
import { createPublicKey } from "crypto";
37+
38+
const app = express();
39+
const PORT = 3000;
40+
const JWT_ISSUER = "https://fa-custom-backend.com";
41+
const JWT_SUBJECT = "user+1@fa-custom-backend.com";
42+
```
43+
44+
## Step 4: Create JWT Generation Endpoint
45+
46+
```typescript
47+
app.get("/jwt", (_: Request, response: Response) => {
48+
// Your transaction payload (hex-encoded)
49+
const SIGNING_PAYLOAD = Buffer.from("Hello world").toString("hex");
50+
51+
const token = jwt.sign(
52+
{ fatxn: SIGNING_PAYLOAD }, // FastAuth transaction claim
53+
{ key: fs.readFileSync("./jwtRS256.key") },
54+
{
55+
expiresIn: "1h",
56+
algorithm: "RS256",
57+
issuer: JWT_ISSUER,
58+
subject: JWT_SUBJECT,
59+
},
60+
);
61+
62+
response.status(200).send(token);
63+
});
64+
```
65+
66+
## Step 5: Start Server and Extract Public Key
67+
68+
```typescript
69+
app.listen(PORT, () => {
70+
console.log("Server running at PORT: ", PORT);
71+
console.log("Jwt issuer: ", JWT_ISSUER);
72+
73+
// Extract public key components for contract configuration
74+
const publicKey = createPublicKey(fs.readFileSync("./jwtRS256.pub"));
75+
const jwk = publicKey.export({ format: "jwk" });
76+
77+
console.log("Jwt public key [n]: ", jwk.n);
78+
console.log("Jwt public key [e]: ", jwk.e);
79+
}).on("error", (error: Error) => {
80+
throw new Error(error.message);
81+
});
82+
```
83+
84+
## Step 6: Run the Server
85+
86+
```bash
87+
# Compile TypeScript
88+
npx tsc index.ts
89+
90+
# Run the server
91+
node index.js
92+
```
93+
94+
## Step 7: Test JWT Generation
95+
96+
```bash
97+
# Get JWT token
98+
curl http://localhost:3000/jwt
99+
```
100+
101+
## Next Steps
102+
103+
1. Customize the `SIGNING_PAYLOAD` with your actual transaction data
104+
2. Implement user authentication before JWT generation
105+
3. Deploy your [JwtRS256Guard contract](./jwt-rs256-guard) with your custom jwt verification logic
106+
4. Register your guard in the JwtGuardRouter contract
107+
5. Test your integration with the FastAuth contract
108+
109+
## Code
110+
111+
You can find the complete code in the [examples](https://github.com/Peersyst/fast-auth/tree/main/examples/custom-backend) folder.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# Integrate your custom backend
1+
# Custom Backend
2+
3+
:::caution
4+
5+
This page is under construction.
6+
7+
:::

docs/docs/integrations/dapp.md

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

docs/docs/integrations/getting-started.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# JwtRS256Guard contract
2+
3+
:::caution
4+
5+
This page is under construction.
6+
7+
:::

docs/docs/integrations/overview.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Overview
2+
3+
FastAuth provides multiple integration options to suit different application architectures and authentication needs. Choose the integration type that best fits your use case:
4+
5+
## Auth0 Integration
6+
7+
Integrate with Auth0 to leverage their authentication infrastructure for secure JWT-based authentication. This integration provides a seamless login experience and handles JWT token generation and validation for your users.
8+
9+
[Learn more about Auth0 integration →](./auth0.md)
10+
11+
## Custom Backend Integration
12+
13+
Build your own authentication backend with full control over the JWT signing and validation process. This integration gives you the flexibility to implement custom authentication logic while still benefiting from FastAuth's transaction signing capabilities.
14+
15+
[Learn more about Custom Backend integration →](./custom-backend.md)
16+
17+
## Next Steps
18+
19+
1. Choose the integration type that matches your needs
20+
2. Follow the specific integration guide for detailed implementation steps
21+
3. Check out the [examples](https://github.com/Peersyst/fast-auth/tree/main/examples) for reference implementations

0 commit comments

Comments
 (0)