ueberauth / ueberauth_github

GitHub OAuth2 Strategy for Überauth
MIT License
102 stars 53 forks source link

GitHub API Requires User-Agent Header #73

Closed thepratt closed 1 year ago

thepratt commented 1 year ago

Steps to Reproduce

  1. Setup a new phoenix project using dependencies and a new github OAuth2 project

      {:ueberauth_github, github: "ueberauth/ueberauth_github", tag: "v0.8.2"},
      {:ueberauth, "== 0.10.3"},
  2. emulate route/controlelr setup in https://github.com/ueberauth/ueberauth_example

  3. attempt to log in with github

Expected Result

To have an authenticated result.

The workaround is to append headers picked up by the OAuth client to the config. Should this be copy added to the readme to help new users with setup or an explicit default+override always sent - as GitHub now looks for this header?

config :ueberauth, Ueberauth.Strategy.Github.OAuth,
...
  headers: [
    "user-agent": "something"
  ]

Actual Result

%OAuth2.Response{
  status_code: 403,
  headers: [
    {"cache-control", "no-cache"},
    {"connection", "close"},
    {"content-type", "text/html; charset=utf-8"},
    {"strict-transport-security", "max-age=31536000"},
    {"x-content-type-options", "nosniff"},
    {"x-frame-options", "deny"},
    {"x-xss-protection", "0"},
    {"content-security-policy", "default-src 'none'; style-src 'unsafe-inline'"}
  ],
  body: "\r\nRequest forbidden by administrative rules. Please make sure your request has a User-Agent header (https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required). Check https://developer.github.com for other possible causes.\r\n"
}

Links to https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#user-agent-required

The error has been hidden by https://github.com/ueberauth/ueberauth_github/blob/master/lib/ueberauth/strategy/github.ex#L267 , which should probably also be logged.

C3sarRC commented 1 year ago

Is this still maintained? i stumbled across the same exact problem