{"id":15509767,"url":"https://github.com/willin/remix-auth-afdian","last_synced_at":"2025-04-23T02:51:27.740Z","repository":{"id":197748023,"uuid":"699267521","full_name":"willin/remix-auth-afdian","owner":"willin","description":"爱发电 OAuth 登录 Remix v2 版本。A AfdianStrategy for Remix Auth, based on the OAuth2Strategy","archived":false,"fork":false,"pushed_at":"2024-01-05T06:17:20.000Z","size":168,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T16:39:17.363Z","etag":null,"topics":["afdian","oauth","remix","sdk","sso"],"latest_commit_sha":null,"homepage":"https://remix-auth-afdian.willin.wang/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"willin","custom":"https://afdian.net/@willin"}},"created_at":"2023-10-02T09:38:49.000Z","updated_at":"2024-09-01T16:15:21.000Z","dependencies_parsed_at":"2023-10-02T10:08:04.537Z","dependency_job_id":"5a46c80e-66c5-4a2a-9bee-662a54d2d2f4","html_url":"https://github.com/willin/remix-auth-afdian","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":0.4,"last_synced_commit":"25edac621db34de6ac3c6327494eb2c07721ad77"},"previous_names":["willin/remix-auth-afdian"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremix-auth-afdian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremix-auth-afdian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremix-auth-afdian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremix-auth-afdian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willin","download_url":"https://codeload.github.com/willin/remix-auth-afdian/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250360248,"owners_count":21417717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["afdian","oauth","remix","sdk","sso"],"created_at":"2024-10-02T09:43:48.355Z","updated_at":"2025-04-23T02:51:27.724Z","avatar_url":"https://github.com/willin.png","language":"TypeScript","funding_links":["https://github.com/sponsors/willin","https://afdian.net/@willin"],"categories":[],"sub_categories":[],"readme":"# AfdianStrategy \n\nThe Afdian strategy is used to authenticate users against a Afdian account. It extends the OAuth2Strategy.\n\n## Supported runtimes\n\n| Runtime    | Has Support |\n| ---------- | ----------- |\n| Node.js    | ✅          |\n| Cloudflare | ✅          |\n\n## Usage\n\n### Create an OAuth application\n\nFollow the steps on [the Afdian（爱发电） documentation](https://afdian.net/p/010ff078177211eca44f52540025c377) to create a new application and get a client ID and secret.\n\n### Create the strategy instance\n\n```ts\nimport { AfdianStrategy } from \"remix-auth-afdian\";\n\nlet afdianStrategy = new AfdianStrategy(\n  {\n    clientID: \"YOUR_CLIENT_ID\",\n    clientSecret: \"YOUR_CLIENT_SECRET\",\n    callbackURL: \"https://example.com/auth/afdian/callback\",\n  },\n  async ({ accessToken, extraParams, profile }) =\u003e {\n    // Get the user data from your DB or API using the tokens and profile\n    return User.findOrCreate({ email: profile.emails[0].value });\n  }\n);\n\nauthenticator.use(afdianStrategy);\n```\n\n### Setup your routes\n\n```tsx\n// app/routes/login.tsx\nexport default function Login() {\n  return (\n    \u003cForm action=\"/auth/afdian\" method=\"post\"\u003e\n      \u003cbutton\u003eLogin with Afdian(爱发电 )\u003c/button\u003e\n    \u003c/Form\u003e\n  );\n}\n```\n\n```tsx\n// app/routes/auth.afdian.tsx\nimport type { ActionArgs } from \"@remix-run/node\";\nimport { redirect } from \"@remix-run/node\";\nimport { authenticator } from \"~/auth.server\";\n\nexport async function loader() {\n  return redirect(\"/login\");\n}\n\nexport async function action({ request }: ActionArgs) {\n  return authenticator.authenticate(\"afdian\", request);\n};\n```\n\n```tsx\n// app/routes/auth.afdian.callback.tsx\nimport type { LoaderArgs } from \"@remix-run/node\";\nimport { authenticator } from \"~/auth.server\";\n\nexport async function loader({ request }: LoaderArgs) {\n  return authenticator.authenticate(\"afdian\", request, {\n    successRedirect: \"/dashboard\",\n    failureRedirect: \"/login\",\n  });\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fremix-auth-afdian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillin%2Fremix-auth-afdian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fremix-auth-afdian/lists"}