All Projects → almassapargali → Sphinx

almassapargali / Sphinx

Licence: MIT license
Authorization library for Phoenix web framework

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Sphinx

Authex
Authex is an opinionated JWT authentication and authorization library for Elixir.
Stars: ✭ 73 (+284.21%)
Mutual labels:  phoenix, auth, authorization
Fosite
Extensible security first OAuth 2.0 and OpenID Connect SDK for Go.
Stars: ✭ 1,738 (+9047.37%)
Mutual labels:  auth, authorization
Node Rate Limiter Flexible
Node.js rate limit requests by key with atomic increments in single process or distributed environment.
Stars: ✭ 1,950 (+10163.16%)
Mutual labels:  auth, authorization
Redis Adapter
Redis adapter for Casbin
Stars: ✭ 167 (+778.95%)
Mutual labels:  auth, authorization
Simpleacl
Simple ACL for PHP
Stars: ✭ 105 (+452.63%)
Mutual labels:  auth, authorization
Node Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
Stars: ✭ 1,757 (+9147.37%)
Mutual labels:  auth, authorization
keeper
Flexible and Simple authentication solution for Phoenix
Stars: ✭ 27 (+42.11%)
Mutual labels:  phoenix, authorization
Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (+315.79%)
Mutual labels:  auth, authorization
Mosquitto Go Auth
Auth plugin for mosquitto.
Stars: ✭ 212 (+1015.79%)
Mutual labels:  auth, authorization
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+14442.11%)
Mutual labels:  auth, authorization
bouncer
Token-based authorization and session management for Phoenix (Elixir)
Stars: ✭ 27 (+42.11%)
Mutual labels:  phoenix, authorization
Sentinel
A framework agnostic authentication & authorization system.
Stars: ✭ 1,354 (+7026.32%)
Mutual labels:  auth, authorization
Jcasbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Java
Stars: ✭ 1,335 (+6926.32%)
Mutual labels:  auth, authorization
Graphql Directive Auth
GraphQL directive for handling auth
Stars: ✭ 120 (+531.58%)
Mutual labels:  auth, authorization
Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Golang
Stars: ✭ 10,872 (+57121.05%)
Mutual labels:  auth, authorization
Vuejs2 Authentication Tutorial
Stars: ✭ 144 (+657.89%)
Mutual labels:  auth, authorization
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (+173.68%)
Mutual labels:  auth, authorization
Next Authentication
Authentication & Authorization library for the Next.js framework
Stars: ✭ 55 (+189.47%)
Mutual labels:  auth, authorization
Huge
Simple user-authentication solution, embedded into a small framework.
Stars: ✭ 2,125 (+11084.21%)
Mutual labels:  auth, authorization
Bodyguard
Simple authorization conventions for Phoenix apps
Stars: ✭ 523 (+2652.63%)
Mutual labels:  phoenix, authorization

Sphinx

An authorization libriary for Phoenix application inspired by CanCan, Canary, and others. It follows Convention over Configuration design, yet allowing full customizations.

Read the docs

Installation

  1. Add sphinx to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:sphinx, "~> 0.1.0"}]
end
```

Then run mix deps.get to fetch the dependencies.

  1. Configure :repo in your config.exs:
```elixir
config :sphinx, :repo, MyApp.Repo
```

Usage

Say you want to authorize your PostController:

  1. Create web/authorizers/post_authorizer.ex and define authorize? functions for each action in controller like:
```elixir
defmodule MyApp.PostAuthorizer do
  def authorize?(_, :index, Post), do: true

  def authorize?(_, :show, %Post{}), do: true

  def authorize?(%User{}, :create, Post), do: true

  def authorize?(%User{id: id}, action, %Post{author_id: id}) when action in [:update, :delete], do: true

  def authorize?(_, _, _), do: false
end
```
  1. Call plug :authorize inside your PostController. You may want to import Sphinx.Plugs in your web.ex for controller scope.

  2. You can now access post in your controller actions like: conn.assigns.resource if authorization passes, and user gets 403 view if it fails.

  3. Profit!

See plug docs for more options.

Ensuring authorization

If you want to make sure all your requests are authorized, add this in your pipelines:

import Sphinx.Plugs

plug :ensure_authorization

Now, if any your requests is about to return without going through authorization, Sphinx would rise Sphinx.AuthorizationNotPerformedError. You can skip authorization for some of your actions in controller like:

plug :skip_authorization, only: [:index, :show]

License

MIT License, Copyright (c) 2016 Almas Sapargali

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].