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

defoverride for definitions from Assent.Strategy when useing Assent.Strategy.OAuth2.Base #155

Open
paulbalomiri opened this issue Jul 21, 2024 · 1 comment

Comments

@paulbalomiri
Copy link

I'm implementing a provider, which needs an aditional body parameter when calling the token endpoint.
in order to override &Assent.Strategy.callback/2, i think that the additional defoverridable Helpers (or defoverridable callback: 2) is needed, otherwhise the implementation in my custom module is ignored.

** Should this overridable definition not be included in the __using/2 definition of Assent.Strategy.OAuth2.Base?

The use definition defines these behavoiurs:

@behaviour Assent.Strategy
@behaviour unquote(__MODULE__)

The only defoverridable in the Assent.Strategy.OAuth2.Base.__using__/1 Macro is this one:

defoverridable unquote(__MODULE__)

In order to override the callback/2 in my implementation module i need to do this:

defmodule CanteAuth.Assent.Strategy.Anaf do
  use Assent.Strategy.OAuth2.Base
 #Shouldn't this be in Assent.Strategy.OAuth2.Base.__using__/1?
  defoverridable Helpers
 ...
  @impl Helpers
  def callback(config, params) do

Is the macro Assent.Strategy.OAuth2.Base.__using__/1 really missing the line

defoverridable Helpers

or am I missing something obvious, for overriding functions imported from Assent.Strategy?

Thank you for this wonderful library! ❤️

paulbalomiri added a commit to paulbalomiri/assent that referenced this issue Jul 21, 2024
…rategy.OAuth2.Base`

Without this defoverridable callback(config, params) is not overridable
@danschultzer
Copy link
Collaborator

There's no need to as you can just implement a strategy that calls Assent.Strategy.OAuth2 directly:

defmodule CanteAuth.Assent.Strategy.Anaf do
  @behaviour Assent.Strategy

  alias Assent.Strategy.OAuth2

  @impl Assent.Strategy
  def authorize_url(config) do
    OAuth2.authorize_url(config(config))
  end

  defp config(config) do
    # Set defaults here and merge with the config
  end

  @impl Assent.Strategy
  def callback(config, params) do
    OAuth2.callback(config(config), params)
  end

  def fetch_user(config, token), do: OAuth2.fetch_user(config, token)
end

This is essentially for use Assent.Strategy.OAuth2.Base does. We may want to allow setting something similar to the authorization_params for authorize_url/2, e.g. grant_access_token_params.

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

No branches or pull requests

2 participants