Skip to content

Commit 2716070

Browse files
committed
feat: extend remix-auth-oauth2
1 parent 5b7c294 commit 2716070

8 files changed

Lines changed: 5185 additions & 117 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,14 @@ jobs:
5858
run: npm run test -- --ci --coverage --maxWorkers=2
5959

6060
lint:
61-
name: Linter
61+
name: Biome
6262
runs-on: ubuntu-latest
6363
steps:
64-
- name: Checkout repo
65-
uses: actions/checkout@v2
66-
67-
- name: Use Node 14
68-
uses: actions/setup-node@v1
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
- name: Setup Biome
67+
uses: biomejs/setup-biome@v2
6968
with:
70-
node-version: 14
71-
72-
- name: Install dependencies
73-
uses: bahmutov/npm-install@v1
74-
75-
- name: Build
76-
run: npm run build
77-
78-
- name: Lint
79-
run: npm run lint
69+
version: latest
70+
- name: Run Biome
71+
run: biome ci .

README.md

Lines changed: 91 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,107 @@
1-
# Remix Auth - Strategy Template
1+
# remix-auth-guilded
22

3-
> A template for creating a new Remix Auth strategy.
3+
remix-auth strategy for Authlink, an OAuth2 provider for Guilded. If you prefer Next.js, see [next-auth-guilded](https://github.com/GuildedAPI/next-auth-guilded).
44

5-
If you want to create a new strategy for Remix Auth, you could use this as a template for your repository.
5+
## Supported runtimes
66

7-
The repo installs the latest version of Remix Auth and do the setup for you to have tests, linting and typechecking.
7+
| Runtime | Has Support |
8+
| ---------- | ----------- |
9+
| Node.js ||
10+
| Cloudflare ||
811

9-
## How to use it
12+
## How to use
1013

11-
1. In the `package.json` change `name` to your strategy name, also add a description and ideally an author, repository and homepage keys.
12-
2. In `src/index.ts` change the `MyStrategy` for the strategy name you want to use.
13-
3. Implement the strategy flow inside the `authenticate` method. Use `this.success` and `this.failure` to correctly send finish the flow.
14-
4. In `tests/index.test.ts` change the tests to use your strategy and test it. Inside the tests you have access to `jest-fetch-mock` to mock any fetch you may need to do.
15-
5. Once you are ready, set the secrets on Github
16-
- `NPM_TOKEN`: The token for the npm registry
17-
- `GIT_USER_NAME`: The git username you want the bump workflow to use in the commit.
18-
- `GIT_USER_EMAIL`: The email you want the bump workflow to use in the commit.
14+
### Create an Authlink application
1915

20-
## Scripts
16+
Visit https://authlink.app/dev/apps, press "new", and connect your Guilded bot to finalize the application. Add a redirect URI and note down your client ID and secret (you will need to press "reset" to generate a secret). You may also configure a vanity code with preconfigured options, though beware that these can be overridden.
2117

22-
- `build`: Build the project for production using the TypeScript compiler (strips the types).
23-
- `typecheck`: Check the project for type errors, this also happens in build but it's useful to do in development.
24-
- `lint`: Runs ESLint against the source codebase to ensure it pass the linting rules.
25-
- `test`: Runs all the test using Jest.
18+
### Create session storage
2619

27-
## Documentations
20+
```ts
21+
// app/session.server.ts
22+
import { createCookieSessionStorage } from "@remix-run/node";
2823

29-
To facilitate creating a documentation for your strategy, you can use the following Markdown
24+
export const sessionStorage = createCookieSessionStorage({
25+
cookie: {
26+
name: "_session",
27+
sameSite: "lax",
28+
path: "/",
29+
httpOnly: true,
30+
secrets: ["s3cr3t"],
31+
secure: process.env.NODE_ENV === "production",
32+
},
33+
});
3034

31-
```markdown
32-
# Strategy Name
35+
export const { getSession, commitSession, destroySession } = sessionStorage;
36+
```
3337

34-
<!-- Description -->
38+
### Create the strategy instance
39+
40+
```ts
41+
// app/auth.server.ts
42+
import { Authenticator } from "remix-auth";
43+
import { GuildedStrategy, type GuildedUser } from "remix-auth-guilded";
44+
import { sessionStorage } from "~/session.server";
45+
46+
export interface GuildedAuth {
47+
id: string;
48+
name: string;
49+
avatar: string | null;
50+
banner: string | null;
51+
accessToken: string;
52+
refreshToken: string;
53+
}
54+
55+
export const auth = new Authenticator<DiscordAuth>(sessionStorage);
56+
57+
const guildedStrategy = new GuildedStrategy(
58+
{
59+
clientId: "YOUR_CLIENT_ID",
60+
clientSecret: "YOUR_CLIENT_SECRET",
61+
redirectUri: "https://example.com/auth/guilded/callback",
62+
scope: ["identify"],
63+
},
64+
// OR { clientId, clientSecret, vanity: "..." }
65+
async ({
66+
accessToken,
67+
refreshToken,
68+
extraParams,
69+
profile,
70+
}): Promise<DiscordAuth> => {
71+
// This package does not fetch the user for you
72+
const user = await this.getUser(accessToken)
73+
74+
// This goes into your sessionStorage and is also returned by
75+
// this method if successRedirect is not provided
76+
return {
77+
id: user.id,
78+
name: user.name,
79+
avatar: user.avatar,
80+
banner: user.banner,
81+
accessToken,
82+
refreshToken,
83+
};
84+
},
85+
);
86+
87+
auth.use(guildedStrategy);
88+
```
3589

36-
## Supported runtimes
90+
### Use in a loader
3791

38-
| Runtime | Has Support |
39-
| ---------- | ----------- |
40-
| Node.js ||
41-
| Cloudflare ||
92+
```ts
93+
// app/routes/auth.guilded.callback.tsx
94+
import type { LoaderFunction } from "@remix-run/node";
95+
import { auth } from "~/auth.server";
4296

43-
<!-- If it doesn't support one runtime, explain here why -->
97+
export const loader: LoaderFunction = ({ request }) => {
98+
return auth.authenticate("guilded", request, {
99+
successRedirect: "/dashboard",
100+
failureRedirect: "/login",
101+
});
102+
};
103+
```
44104

45-
## How to use
105+
## Attribution
46106

47-
<!-- Explain how to use the strategy, here you should tell what options it expects from the developer when instantiating the strategy -->
48-
```
107+
Design elements & examples from [remix-auth-discord](https://github.com/JonnyBnator/remix-auth-discord).

biome.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"linter": {
7+
"enabled": true,
8+
"rules": {
9+
"recommended": true
10+
}
11+
},
12+
"formatter": {
13+
"indentStyle": "space"
14+
}
15+
}

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
{
2-
"name": "remix-auth-strategy-template",
3-
"version": "0.0.0",
2+
"name": "remix-auth-guilded",
3+
"version": "1.0.0",
44
"main": "./build/index.js",
55
"types": "./build/index.d.ts",
6+
"repository": {
7+
"url": "https://github.com/GuildedAPI/remix-auth-guilded"
8+
},
9+
"author": {
10+
"name": "shay (shayypy)",
11+
"url": "https://shay.cat"
12+
},
613
"scripts": {
714
"build": "tsc --project tsconfig.json",
815
"typecheck": "tsc --project tsconfig.json --noEmit",
9-
"lint": "eslint --ext .ts,.tsx src/",
16+
"lint": "biome lint .",
17+
"fix": "biome check --apply .",
1018
"test": "jest --config=config/jest.config.ts --passWithNoTests",
1119
"coverage": "npm run test -- --coverage"
1220
},
@@ -31,27 +39,20 @@
3139
"@babel/preset-env": "^7.14.1",
3240
"@babel/preset-react": "^7.13.13",
3341
"@babel/preset-typescript": "^7.13.0",
42+
"@biomejs/biome": "^1.7.1",
3443
"@remix-run/node": "^1.0.3",
3544
"@remix-run/react": "^1.1.1",
3645
"@remix-run/server-runtime": "^1.0.0",
3746
"@types/jest": "^26.0.23",
38-
"@typescript-eslint/eslint-plugin": "^4.23.0",
39-
"@typescript-eslint/parser": "^4.23.0",
4047
"babel-jest": "^26.6.3",
41-
"eslint": "^7.26.0",
42-
"eslint-config-prettier": "^8.3.0",
43-
"eslint-plugin-jest": "^24.3.6",
44-
"eslint-plugin-jest-dom": "^3.9.0",
45-
"eslint-plugin-prettier": "^3.4.0",
46-
"eslint-plugin-unicorn": "^32.0.1",
4748
"jest": "^26.6.3",
4849
"jest-fetch-mock": "^3.0.3",
49-
"prettier": "^2.3.2",
5050
"react": "^17.0.2",
5151
"ts-node": "^9.1.1",
5252
"typescript": "^4.3.5"
5353
},
5454
"dependencies": {
55-
"remix-auth": "^3.0.0"
55+
"remix-auth": "^3.0.0",
56+
"remix-auth-oauth2": "^1.11.2"
5657
}
5758
}

0 commit comments

Comments
 (0)