OauthService
Uses Google, Yandex Oauth2 services to authenticate users.
##Installation
Use rails g oauth_service:install
to install basic config
Set all Oauth2 variables in OauthService.providers_keys
config.providers_keys = {
:google => {
:auth_url => ENV["GOOGLE_AUTH_URL"],
:client_id => ENV["GOOGLE_CLIENT_ID"],
:client_secret => ENV["GOOGLE_CLIENT_SECRET"],
:info_url => ENV["GOOGLE_INFO_URL"],
:scopes => ENV["GOOGLE_SCOPES"],
:token_url => ENV["GOOGLE_TOKEN_URL"]
}
}
Set all Oauth2 services to allow the following urls: <your_server_name>/<OauthService.redirect_uri>/<provider_name_downcased>?format=<format_name>
OauthService.redirect_uri
should be changed according to <your_mount_path>
Set return format using OauthService.request_format
. Default is "json"
##How to use
Authentication process
-
User clicks a link created by
<your_provider>.auth_uri
-
User is sent to oauth service authentication page
-
After authentication user is sent to link generated by method
-
Server retrieves all relevant user information
-
user_name
,user_email
,api
are saved in session. -
user_name
,user_email
variables are returned
Logout process
-
User is sent to
<your_server_name>/<your_mount_path>/logout
-
user_name
,user_email
,api
are removed from session.
##Creating new Oauth providers To create a new provider you need:
-
Create a class which inherits from OauthService::Provider
-
Override OauthService::Provider.get_info
-
Add your provider keys to
OauthService.providers_keys
-
Add your provider class to
OauthService.avaliable_providers