danschultzer

danschultzer

Pow Core Team

PowAssent: Instant multi-provider support for Pow

Multi-provider support for Pow with out-of-the-box support for many providers. I finally got a 0.1.0 release up today, and I hope some of you will find it useful :smile:

Please let me know if there’s anything that can be improved in the docs or with features. Thanks!

https://github.com/danschultzer/pow_assent
https://hexdocs.pm/pow_assent/

Pow thread: Pow: Robust, modular, extendable user authentication and management system

PowAssent details

Base strategies

  • OAuth 1.0
  • OAuth 2.0

Strategies

  • Azure AD
  • Basecamp
  • Discord
  • Facebook
  • Github
  • Google
  • Instagram
  • Slack
  • Twitter
  • VK

Few dependencies

PowAssent has nearly no dependencies. :httpc is used as the default HTTP client with built-in SSL validation!

Mint can be added for HTTP/2 support.

Can PowAssent be used without Pow?

Yes! You can use any strategy directly:

config = [
  client_id: "REPLACE_WITH_CLIENT_ID",
  client_secret: "REPLACE_WITH_CLIENT_SECRET",
]

{:ok, %{conn: conn, url: url}} = PowAssent.Strategy.Github.authorize_url(config, conn)

case PowAssent.Strategy.Github.callback(config, conn, params) do
  {:ok, %{conn: conn, user: user}} -> # …
  {:error, reason} -> # …
end

I’ve been using this technique for a lean super admin login.

What about Ueberauth?

You can use Ueberauth with Pow, or add a custom strategy that uses Ueberauth underneath!

However, most strategies uses the OAuth protocols, and it’s much easier to just add your custom strategy. It takes no time to set up. Pull requests are welcome!

A big difference from Ueberauth is that PowAssent is self contained. Strategies are built-in and consists of very little code. They rely on base strategies like OAuth or OAuth2 to do the heavy lifting. All strategies are consistent, and e.g. switching out underlying HTTP client or JSON library is no problem. Unfortunately with Ueberauth you’ll have several different dependencies that each handle things differently. This may also cause dependency conflicts.

Adding a custom strategy

Provider support is super easy. You just need to write one (tiny) module:

defmodule MyApp.CustomStrategy do
  use PowAssent.Strategy.OAuth2

  def default_config(_config) do
    [
      site: "https://api.example.com",
      user_url: "/authorization.json"
    ]
  end

  def normalize(_config, user) do
    %{
      "uid"   => user["id"],
      "name"  => user["name"],
      "email" => user["email"]
    }
  end
end

And then add it to your providers:

config :my_app, :pow_assent,
  providers: [
    custom_strategy: [
      client_id: "REPLACE_WITH_CLIENT_ID",
      client_secret: "REPLACE_WITH_CLIENT_SECRET",
      strategy: MyApp.CustomStrategy
    ]
  ]

Happy coding :rocket:

Most Liked

danschultzer

danschultzer

Pow Core Team

Pow 0.2.0 released

Changelog: Github
Hex: https://hex.pm/packages/pow_assent/0.2.0

This release contains several breaking changes. The plug methods and controllers have been streamlined so they are much easier to work with. However, you don’t need to change a thing unless you’ve a very customized 0.1.0 setup.

Removed Plug.Conn from strategies

Strategies no longer uses plug conn param. Now you only have to pass configuration and params. This means that PowAssent strategies can be used in any context with no expectation for any dependency!

PowInvitation

Support for the new PowInvitation extension in Pow 1.0.3!

It’s plug n’ play. Zero configuration.

danschultzer

danschultzer

Pow Core Team

Thanks! It’s in the readme, but it’s kind of hidden towards the end: https://github.com/danschultzer/pow#other-libraries

Maybe it would be better with a reference to it in the Extensions section.

danschultzer

danschultzer

Pow Core Team

You’re right, the user identity is never updated, only created or deleted. When there’s a match for :provider and :uid, the user will just be authenticated. I’m not sure what the solution should be, so I’ve just opened an issue on github I’ll give this some thought.

blatyo

blatyo

Conduit Core Team

I left a comment on the issue. https://github.com/danschultzer/pow_assent/issues/69

Hopefully that’s useful.

Where Next?

Popular in Libraries Top

RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 11851 134
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
engineeringdept
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement