defmodule WhoNeedHelp.SocialOAuth.GithubStrategy do
  @moduledoc false

  use Assent.Strategy.OAuth2.Base

  @impl true
  def default_config(_config) do
    [
      base_url: "https://api.github.com",
      authorize_url: "https://github.com/login/oauth/authorize",
      token_url: "https://github.com/login/oauth/access_token",
      user_url: "/user",
      auth_method: :client_secret_post,
      code_verifier: true,
      authorization_params: []
    ]
  end

  @impl true
  def normalize(_config, user) do
    {:ok,
     %{
       "sub" => user["id"],
       "name" => user["name"],
       "preferred_username" => user["login"],
       "profile" => user["html_url"],
       "picture" => user["avatar_url"]
     }}
  end
end
