Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Strategy with CF Workers #79

Closed
lgastler opened this issue Dec 11, 2021 · 0 comments · Fixed by #81
Closed

GitHub Strategy with CF Workers #79

lgastler opened this issue Dec 11, 2021 · 0 comments · Fixed by #81

Comments

@lgastler
Copy link
Contributor

Currently there is an error when you want to use the GitHub Strategy from remix-auth with Cloudflare Workers.

The error occurs when trying to retrieve profile information from the GitHub API. This request fails with an error status of 403. The error occurs because GitHub needs to force a user agent header, which is apparently not sent by the worker fetch. (https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required)

The solution is quite simple, just add a user agent header to the profile request.

However, I'm not sure how best to implement it. You could either set a fixed User-Agent (e.g. remix-auth-app) or forward the User-Agent from the incoming request. I think it makes no sense to have it configured as it probably only affects CloudFlare workers at the moment and other platforms automatically fill in the user agent.

protected async userProfile(accessToken: string): Promise<GitHubProfile> {
let response = await fetch(this.userInfoURL, {
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: `token ${accessToken}`,
},
});

let response = await fetch(this.userInfoURL, {
  headers: {
     Accept: "application/vnd.github.v3+json",
     Authorization: `token ${accessToken}`,
+    User-Agent: "remix-auth-app"
  },
});

Heres a example repo with a custom github.ts to fix the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant