Class: G5::UserExporter
- Inherits:
-
Object
- Object
- G5::UserExporter
- Defined in:
- lib/devise_g5_authenticatable/g5/user_exporter.rb
Overview
Exports all users to the G5 auth server. Assumes presence of User model with uid and provider attributes.
Instance Method Summary collapse
-
#export ⇒ String
Export local users to the G5 Auth server.
-
#initialize(options = {}) ⇒ UserExporter
constructor
A new instance of UserExporter.
Constructor Details
#initialize(options = {}) ⇒ UserExporter
Returns a new instance of UserExporter.
16 17 18 19 20 21 22 |
# File 'lib/devise_g5_authenticatable/g5/user_exporter.rb', line 16 def initialize( = {}) @client_id = [:client_id] @client_secret = [:client_secret] @redirect_uri = [:redirect_uri] @endpoint = [:endpoint] @authorization_code = [:authorization_code] end |
Instance Method Details
#export ⇒ String
Export local users to the G5 Auth server. A record will be created in G5 Auth and associated with each local User. Password data is not automatically exported, but is returned in a dump of SQL update statements suitable for executing on the G5 Auth server.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/devise_g5_authenticatable/g5/user_exporter.rb', line 31 def export update_statements = User.all.collect do |user| # The user won't actually be able to log in with their usual password, # but at least it won't be set to a guessable value auth_user = auth_client.create_user(email: user.email, password: user.encrypted_password) update_local_user(user, auth_user) update_sql(auth_user.id, user.encrypted_password) end update_statements.join("\n") end |