Module: Google::IdentityToolkit::Helpers
- Defined in:
- lib/google/identity_toolkit/helpers.rb
Instance Method Summary collapse
-
#account_chooser(element_id, options = {}) ⇒ String
Generate javascript for configuring the identity toolkit button.
- #show_current_user(options = {}) ⇒ Object
Instance Method Details
#account_chooser(element_id, options = {}) ⇒ String
Generate javascript for configuring the identity toolkit button
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/google/identity_toolkit/helpers.rb', line 22 def account_chooser(element_id, = {}) callback_url = Addressable::URI.parse([:callback_url] || Google::IdentityToolkit.callback_url) params = callback_url.query_values || {} callback_url.query_values = params.merge("mobile" => "1") if [:mobile] js = <<-EOF window.google.identitytoolkit.setConfig({ developerKey: "#{[:api_key] || Google::IdentityToolkit.api_key}", companyName: "#{[:site_name]}", callbackUrl: "#{callback_url}", userStatusUrl: "#{callback_url}", loginUrl: "#{callback_url}", federatedSignupUrl: "#{[:federated_signup_url] || [:signup_url] || '/signup' }", signupUrl: "#{[:signup_url] || '/signup'}", homeUrl: "#{[:home_url] || '/' }", logoutUrl: "#{[:logout_url] || '/logout'}", realm: "#{[:realm]}", language: "#{[:language] || 'en'}", idps: ["Gmail", "AOL", "Hotmail", "Yahoo"], tryFederatedFirst: #{[:try_federated_first] || false}, useCachedUserStatus: #{[:use_cached_status] || false} }); $('#{element_id}').accountChooser(); EOF end |
#show_current_user(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/google/identity_toolkit/helpers.rb', line 47 def show_current_user(={}) js = "" user = [:user] || Google::IdentityToolkit.current_user if user js = <<-EOF window.google.identitytoolkit.updateSavedAccount({ email: '#{user[:email]}', displayName: '#{user[:display_name]}', photoUrl: '#{user[:photo_url]}' }); window.google.identitytoolkit.showSavedAccount('#{user[:email]}'); EOF end js end |