Omniauth strategy for arise at ENSIIE
Add these lines to your application's Gemfile:
gem 'omniauth'
gem 'omniauth-oauth'
gem 'omniauth-arise', git: 'https://github.com/Prince-Leto/omniauth-arise.git'
And then execute:
$ bundle
Create a file /config/initializers/omniauth.rb
. Don't forget to add it to your .gitignore
file.
#/config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :arise, 'your_id', 'your_secret', [your_methods_list] # (ex: ["get_identifiant", "get_nom", ...])
end
Add routes into your route file :
#/config/routes.rb
Rails.application.routes.draw do
get '/auth/:provider/callback', to: 'sessions#signin'
# You can add failure route too : get '/auth/failure'. Omniauth is redirecting to this url when something wrong happend
# And add a sign out route
end
Now you can use omniauth into a session controller
def signin
infos = request.env['omniauth.auth']['extra']['infos']
session[:arise_id] = infos["get_identifiant"]
redirect_to root_url, notice: "Vous êtes connecté"
end
def signout
reset_session
redirect_to 'https://oauth.iiens.net/?page=logout&url=' + root_url
end
In production, you need to add arise certificate to trusted authoritizes.
On Debian do :
Add Arise certificate to /usr/local/share/ca-certificates
Run update-ca-certificates
- Fork it ( https://github.com/Prince-Leto/omniauth-arise/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