kemal-auth-token alternatives and similar shards
Based on the "Framework Components" category.
Alternatively, view kemal-auth-token alternatives based on common mentions on social networks and blogs.
-
shrine.cr
File Attachment toolkit for Crystal applications. Heavily inspired by Shrine for Ruby. -
Exception Page
An exceptional exception page for Crystal web libraries and frameworks -
artanis
Sinatra-like DSL for the Crystal language (abusing macros) -
praetorian
A minimalist Crystal authorization system inspired by https://github.com/varvet/pundit. -
motion.cr
Motion is a framework for building reactive, real-time frontend UI components in your Amber application using pure Crystal that are reusable, testable & encapsulated. -
device_detector
Crystal shard for device detection by User-Agent string -
mochi
Mochi is a authentication shard inspired by devise. Mochi is designed for the Amber framework with support for both Granite & Jennifer ORM's. -
mime-types.cr
MIME Types for Crystal :: A port of the Ruby MIME::Types library -
Athena Event Dispatcher
A Mediator and Observer pattern event library -
request_id
Middleware for generates / pick up a unique request ID for Crystal servers. -
Athena Negotiation
Framework agnostic content negotiation library
Collect and Analyze Billions of Data Points in Real Time
Do you think we are missing an alternative of kemal-auth-token or a related project?
README
kemal-auth-token
Gives the current_user
to kemal
.
Installation
Add this to your application's shard.yml
:
dependencies:
kemal-auth-token:
github: akwiatkowski/kemal-auth-token
Usage
Initializer
First, you need to initialize middleware.
auth_token_mw = Kemal::AuthToken.new
Sign in
You must provide a way to sign user in. It is your choice how would you like to do it (fetch from DB, have predefined, ...).
You must return UserHash
it is alias of Hash(String, (String | Int32 | Nil | Bool))
.
You can use login, id, whatever instead of an email
.
auth_token_mw.sign_in do |email, password|
User.sign_in(email, password)
end
There is path to sign in, which you can change if you want.
auth_token_mw.path = "/sign_in" # default value
If you want sign in just execute POST request:
http = HTTP::Client.new("localhost", Kemal.config.port)
result = http.post_form("/sign_in", {"email" => "[email protected]", "password" => "password" })
json = JSON.parse(result.body)
Which return
{"token":"some weird characters"}
Using token
Next request can utilize token
based authentication. You must provide
it within HTTP headers.
headers = HTTP::Headers.new
headers["X-Token"] = "some weird characters"
http = HTTP::Client.new("localhost", Kemal.config.port)
result = http.exec("GET", "/path", headers)
Get current user
Kemal
needs a way how to get user information from JWT token. You must
tell how it should do.
auth_token_mw.load_user do |jwt_payload|
User.load_user(jwt_payload)
end
Keep in mind that jwt_payload
is Hash(String, JSON::Type)
.
You need to provide way to get user information from object (UserHash
) stored in
JWT token here. That information should be presented also as UserHash
.
Later you can access current user information within Kemal
code as below:
get "/current_user" do |env|
env.current_user.to_json
end
Final note
Please read spec
file :)
Development
TODO: Write development instructions here
Contributing
- Fork it ( https://github.com/akwiatkowski/kemal-auth-token/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- akwiatkowski Aleksander Kwiatkowski - creator, maintainer