defmodule Ueberauth.Strategy.AzureAD.OAuth do use OAuth2.Strategy alias OAuth2.Client alias OAuth2.Strategy.AuthCode @defaults [ strategy: __MODULE__, site: "https://graph.microsoft.com", request_opts: [ssl_options: [versions: [:"tlsv1.2"]]] ] def client(opts \\ []) do config = Application.get_env(:ueberauth, Ueberauth.Strategy.AzureAD.OAuth) urls = [ authorize_url: "https://login.microsoftonline.com/#{config[:tenant_id]}/oauth2/v2.0/authorize", token_url: "https://login.microsoftonline.com/#{config[:tenant_id]}/oauth2/v2.0/token", ] @defaults |> Keyword.merge(config) |> Keyword.merge(opts) |> Keyword.merge(urls) |> Client.new() end def authorize_url!(params \\ [], opts \\ []) do opts |> client |> Client.authorize_url!(params) end def get_token!(params \\ [], opts \\ []) do opts |> client |> Client.get_token!(params) end # oauth2 Strategy Callbacks def authorize_url(client, params) do AuthCode.authorize_url(client, params) end def get_token(client, params, headers) do client |> put_param(:client_secret, client.client_secret) |> put_header("Accept", "application/json") |> AuthCode.get_token(params, headers) end end