From 9eeb60b5cd1739f0243bf72df6d32987dfde2ea8 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Fri, 20 Jun 2014 15:26:15 +0300 Subject: [PATCH 1/3] Documentation about using OpenID --- README.md | 14 ++++++++++---- config/secrets.yml.example | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6a5d210f..05e8d591 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ git clone https://github.com/openSUSE/osem.git bundle install ``` 3. Install ImageMagick from your distribution repository -4. Generate secret key for devise and the rails app with +4. Generate secret key for devise and the rails app with ``` rake secret ``` @@ -39,12 +39,18 @@ bundle exec rake db:setup ``` rails server ``` -8. Visit the APP at +8. Visit the APP at ``` http://localhost:3000 ``` 9. Sign up, the first user will be automatically assigned the admin role. +10. Use openID +In order to use the OpenID feature you need to register your application with the providers +(Google and Facebook) and enter their API keys in config/secrets.yml file, changing the existing sample values. +You can register as a devoloper with Google from https://code.google.com/apis/console#:access +You can register as a devoloper with Facebook from https://developers.facebook.com/ + ### Run OSEM in production We recommend to run OSEM in production with [mod_passenger](https://www.phusionpassenger.com/download/#open_source) and the [apache web-server](https://www.apache.org/). There are tons of guides on how to deploy rails apps on various @@ -53,8 +59,8 @@ base operating systems. Check Google ;-) ## Documentation OSEM is extensively (some would say maniacally ;-) documented. You can generate a nice HTML documentation with ''rdoc'' ``` -bundle exec rdoc --op doc/app --all -f fivefish app -xdg-open doc/app/index.html +bundle exec rdoc --op doc/app --all -f fivefish app +xdg-open doc/app/index.html ``` ## Testing diff --git a/config/secrets.yml.example b/config/secrets.yml.example index d88180d4..a98d4779 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -5,11 +5,17 @@ defaults: &defaults secret_key_base: '12345' # For devise login tokens - devise_secret_key: '12345' + devise_secret_key: '12345' # Your errbit API key # errbit_key: '12345' + google_key: 'changeme' + google_secret: 'changeme' + + facebook_key: 'changeme' + facebook_secret: 'changeme' + development: <<: *defaults From 043ba75e81dfec12be09bed838f6f510071aa7a4 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Fri, 20 Jun 2014 20:13:56 +0300 Subject: [PATCH 2/3] Only show OpenID links if their keys have been set. --- README.md | 17 ++++++++++++++++- app/views/devise/shared/_openid.html.haml | 7 +++++-- config/secrets.yml.example | 23 +++++++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 05e8d591..c7ad9979 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,23 @@ http://localhost:3000 10. Use openID In order to use the OpenID feature you need to register your application with the providers (Google and Facebook) and enter their API keys in config/secrets.yml file, changing the existing sample values. + You can register as a devoloper with Google from https://code.google.com/apis/console#:access -You can register as a devoloper with Facebook from https://developers.facebook.com/ +You can register as a devoloper with Facebook from https://developers.facebook.com/, +by selecting from the top menu the option 'Apps' -> 'Create a New App' + +Unless you add the key and secret for each provider, you will not be able to see the image that +redirects to the login page of the provider. + +If you add a provider that does not require developers to register their application, you still need +to create two (2) variables, in config/secrets.yml +with the format of providername_key and providername_secret and add some sample text as their values. +Example: +myprovider_key = 'sample data' +myprovider_secret = 'sample data' + +That is required so that the check in app/views/devise/shared/_openid.html.haml will pass and +the image-link to login using the provider will be shown. ### Run OSEM in production We recommend to run OSEM in production with [mod_passenger](https://www.phusionpassenger.com/download/#open_source) diff --git a/app/views/devise/shared/_openid.html.haml b/app/views/devise/shared/_openid.html.haml index e349e434..5d1e6300 100644 --- a/app/views/devise/shared/_openid.html.haml +++ b/app/views/devise/shared/_openid.html.haml @@ -1,4 +1,7 @@ - if devise_mapping.omniauthable? - resource_class.omniauth_providers.each do |provider| - = link_to image_tag("#{provider}.png", size: '32x32') + provider , omniauth_authorize_path(resource_name, provider) - %br + - provider_key = "#{provider}_key" + - provider_secret = "#{provider}_secret" + - unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank? + = link_to image_tag("#{provider}.png", size: '32x32') + provider , omniauth_authorize_path(resource_name, provider) + %br diff --git a/config/secrets.yml.example b/config/secrets.yml.example index a98d4779..0671fb71 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -10,11 +10,26 @@ defaults: &defaults # Your errbit API key # errbit_key: '12345' - google_key: 'changeme' - google_secret: 'changeme' + # Leave the variables' names empty, unless you use the providers, in which case you need to + # register your applicaton and add the actual keys. - facebook_key: 'changeme' - facebook_secret: 'changeme' + # If you add more providers, keep the format of the variables: provider_key, provider_secret + + # Register your appllication with Google from https://code.google.com/apis/console#:access + google_key: '' + google_secret: '' + + # Register your application with Facebook from https://developers.facebook.com/ + facebook_key: '' + facebook_secret: '' + + # Developers do not need to register their application for novell account to work. + # You must, however, leave the sample data there, for the login option to appear. + + novell_key: 'sample data' + novell_secret: 'sample data' + + # If you add more providers that do not require a key, you still have to create the 2 variables with sample data development: <<: *defaults From be1e3293deb0ca8c0cacc9d1ab2a0aa985b3f312 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Sat, 21 Jun 2014 07:42:02 +0300 Subject: [PATCH 3/3] assign values to necessary Rails.application.secrets variables --- spec/support/omniauth_macros.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/support/omniauth_macros.rb b/spec/support/omniauth_macros.rb index 9b9dab39..88b605fe 100644 --- a/spec/support/omniauth_macros.rb +++ b/spec/support/omniauth_macros.rb @@ -2,6 +2,11 @@ module OmniauthMacros # The mock_auth configuration allows you to set per-provider (or default) # authentication hashes to return during integration testing. + Rails.application.secrets.google_key = 'test key google' + Rails.application.secrets.google_secret = 'test secret google' + Rails.application.secrets.facebook_key = 'test key facebook' + Rails.application.secrets.facebook_secret = 'test secret facebook' + def mock_auth_new_user OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new(