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

Reliance on inets? #67

Closed
Bastes opened this issue Nov 13, 2020 · 2 comments · Fixed by #69
Closed

Reliance on inets? #67

Bastes opened this issue Nov 13, 2020 · 2 comments · Fixed by #69

Comments

@Bastes
Copy link

Bastes commented Nov 13, 2020

Hi,

Using assent to authenticate through oauth2 on a micro-app that had no ecto backup nor need to record user information past authorization, I encountered an error after the built succeed:

web_1  | ** (exit) an exception was raised:
web_1  |     ** (UndefinedFunctionError) function :httpc.request/4 is undefined (module :httpc is not available)
web_1  |         :httpc.request(:post, {'https://api.intra.42.fr/oauth/token', [{'User-Agent', 'Assent-0.1.16'}], 'application/x-www-form-urlencoded', 'code=d44d4959376eb30953852cc66cb4ebce50c4018dfda2dc79ebd26414bcac3ab2&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fsession%2Fcallback&grant_type=authorization_code&client_id=54d568770a5f2984fdacf76bcf38d469edbe71b55ccd050dd83a63fd94f0ac6b&client_secret=b237063058109ba31701030463a9a77616fecab6b866e53f1b50e1c03da9d3e5'}, [], [])
web_1  |         (assent) lib/assent/http_adapter/httpc.ex:25: Assent.HTTPAdapter.Httpc.request/5
web_1  |         (assent) lib/assent/strategy.ex:42: Assent.Strategy.request/5
web_1  |         (assent) lib/assent/strategies/oauth2.ex:250: Assent.Strategy.OAuth2.grant_access_token/3
web_1  |         (assent) lib/assent/strategies/oauth2.ex:129: Assent.Strategy.OAuth2.callback/3
# ... here be where the binding was used in my app

That happened during the callback of the oauth2 transaction, and completely baffled me. It looked like something like a missing dependency or something, yet I did not see anything like this in assent's docs, and when I googled it, it looked exactly like the inets lib was missing...

I finally figured out how to fix this, adding inets to the extra_applications:

# in app/mix.exs
  def application do
    [
      # ...
      extra_applications: [
        # ...
        :inets
      ]
    ]
  end

...aaaand... that worked.

Maybe it should be noted in the installation docs that inets is necessary to be started for it to work. I'm willing to make a PR explaining it, but I'd like for someone knowing assent from the inside out to explain why and in which cases it's necessary to have inets as a dependency first (so I don't mislead others either).

So, there. Thank you for that awesome lib by the way.

@danschultzer
Copy link
Collaborator

Good catch, thanks! I've updated the docs 😄

:httpc is optional so I've decided not to load :inets in case you are using another HTTP adapter that doesn't depend on it. No need to load and compile `:inets into the app in that case.

@Bastes
Copy link
Author

Bastes commented Nov 25, 2020

Happy to help :) thanks for the fix.

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.

2 participants