MojeID authentication strategy.
OmniAuth::MojeID is an extension to OmniAuth::OpenID with some useful defaults and added attributes.
gem install omniauth-mojeid
Inside devise.rb
, add a simple line:
config.omniauth :mojeid
This will prompt the user for the default attributes. If you want to configure which attributes to obtain from the user, specify them in the required
and optional
fields.
config.omniauth :mojeid, :required => [:name, :email], :optional => [:city]
See full list of profile attributes.
Use the strategy as a middleware in your application:
require 'omniauth-mojeid'
use Rack::Session::Cookie
use OmniAuth::Strategies::MojeID
If MojeID is one of several authentication strategies, use the OmniAuth Builder:
require 'omniauth-mojeid'
use OmniAuth::Builder do
provider :mojeid
end
By default, the omniauth information during the response handling is stored in ruby-openid's Memory Store. To change this, override the store
option:
require 'omniauth-openid'
require 'openid/store/filesystem'
use OmniAuth::Builder do
provider :mojeid, :store => OpenID::Store::Filesystem.new('/tmp')
end
Create an xml file and make it available at YOUR_URL/xrds.xml
. The file should contain this text (don't forget to replace YOUR_URL):
<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<XRD>
<Service>
<Type>http://specs.openid.net/auth/2.0/return_to</Type>
<URI>***YOUR_URL***/auth/mojeid/callback</URI>
</Service>
</XRD>
</xrds:XRDS>
Simply point users to /auth/mojeid
which will redirect them to MojeID.cz website to prompt them for their profile information.
In the response callback at /auth/mojeid/callback
, the attributes will become available in the ["omniauth.auth"]["info"]
hash. So, to print out user's email, use ["omniauth.auth"]["info"][:email]
.
To learn about the internals please read the specification (in Czech).
By default, mojeid asks user for the following profile attributes:
:required => [:email, :name, :first_name, :last_name]
:optional => [:nickname, :street, :city, :postal_code, :country]
If you want to customize the information, use the attributes listed in the table below.
You can also use the Simple Reg name (as a string) to name the attributes. (Though in my experience the mapping doesn't seem to be working well.)
:required => ['email', 'fullname', :first_name, :last_name, 'dob']
Note that the user can decide if they share the information with you, so even if you request certain fields, they may be empty (nil
).
Also note that you may not request the same attribute both in the required
and optional
fields otherwise an error will be raised.
MIT License