ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - sajmoon/mellon: Authentication module for Plug applications
Authentication module for Plug applications. Contribute to sajmoon/mellon development by creating an account on GitHub.
Visit Site

GitHub - sajmoon/mellon: Authentication module for Plug applications

GitHub - sajmoon/mellon: Authentication module for Plug applications

Mellon

Build Status

An authentication module for Plug applications.

Intallation

defp deps do
  [{:mellon, "~> 0.1.1"}]
end

How to use

See /examples for a working example.

defmodule MyApp do
  import Plug.Conn
  use Plug.Builder

  plug Mellon, validator: {MyApp, :validate, []}, header: "X-AUTH"

  plug :index

  def validate({conn, token}) do
    case token do
      "ValidToken" -> {:ok, {"userdata"}, conn}
      _ -> {:error, [], conn}
  end

  def index(conn, _opts) do
    send_resp(conn, 200, "Secure area")
  end
end

To authenticated for this example using curl you might do the following:

curl --header "X-AUTH: Token: ValidToken" localhost:4000/hello

Configuration

You can configure some parameters while initializing Mellon.

Required

validator: The function that validates the token. Must return {:ok, userdata, conn} if valid and {:error, conn} if not.

Optional

header: The http header used for tokens. Will default to 'Authorization'.

block: Boolean representing if we should return a 401 and stop the chain, if the user is unauthenticated. set block: false, and you can handle displaying a message, oredirecting from the controller.

Return object from validator

The validator can return some options.

All requests that are authenticated should return

{:ok, cargo, conn}

cargo can be any object that you would like to pass along. it will be assigned to the request so you can access it later in your controller. It will be assigned to :credentials. To access it later you could do the following: conn.assigns[:credentials].

If authentication fails you should return {:error, options, conn}.

Where options is a Keyword containing status: and message. Both are optional.

In case you want a custom Unauthenticated message include [message: 'Get out of here!']

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory