Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ after_success:
- test -z "$DEPLOY_DOCS" || git push origin source
env:
global:
- STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/4xz3y2Hrid4aqp5YwbNTvk
- secure: VMjIMI42vIPTMPTr0fnzSPiIjzuSAnT7iNWjhAXP9WsdaCmxwHp1vOlry4QuX8DzpKHv2MQubeUN/UA227Nk1xn+CVu9mujWOqvvjmL9m20wMJvwT4ctn7zG+FJK76id9TEyx0mCTlH4ZrRoDMGfM9yzhpsg8FtSebBDdHxePaM=
- secure: IhR6H9qxmxCDNbLK0ebYuIXQRsGA/JhD6In4V/hnSMJ8lPi2kwRn6eKclNCHGNjcy6QF1V5vddKIfKOkFFZvIyP26reygTX1g5Mfa8SqTGKh3DAW4WP+T+yaE4z4UBDK1zZpbV0Zbkw/HC0xeD8UPnjRzERX1LVZp1qeEjhQrks=
- secure: MWBpUnXAj1nkPXOy17IOOY/HwQ7nsEtaNRzvbwNt2Nvr8vtsClcLlu3dXF3suex9k1ZG1c0SuNQdUOQmiOUvobUOPa2PgKcjzRcw8NhIuKxZAZLNKqtNIWsDzlf5zDuUIUkCVewGtsjUZJLIRi/1XZLFsbjZYvEdc/ZPM5LoPo8=
- STORMPATH_APPLICATION_HREF=https://api.stormpath.com/v1/applications/4xz3y2Hrid4aqp5YwbNTvk
- secure: fuZU/DCNpezx1qrhpt/b+eeZRF83AiAwJnUNgA0D2fH4KGleN+BGfz5wEy6oOu5QKDWWAWepHDuwUjTP6QL504QId8+QZbycr52tFM0NXDSzpzhGkoaAEIALjuJ+DBto032yr8hoFjM+P5M1057p2jZKyr5CMkB66j4g3oWwA5k=
- secure: F0+m4wWKgqZLWpouKwn3BQB1/DXkbwmKEE6E+XFSEJB3rIsf8J4stP6OslqGmkdOzbx/4Dl/V3EXMmWk6R8hnQ5rmr60FGN6FBXUTA+s/9ZULl1I3+J/PsV5azFUwuP+87hbS9QQTVxbG7S3Gpmuy3JCSjySQ4vfXo8fZPz6Plk=
matrix:
include:
- env: BUILD_DOCS=true
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ group :test do
gem 'webmock'
gem 'vcr', '3.0.1'
gem 'ammeter', git: 'https://github.com/alexrothenberg/ammeter'
gem 'simplecov', require: false
gem 'coveralls', require: false
gem 'json_matchers'
gem 'match_json', '0.0.5'
gem 'capybara'
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Build Status](https://travis-ci.org/stormpath/stormpath-rails.svg?branch=master)](https://travis-ci.org/stormpath/stormpath-rails)
[![Coverage Status](https://coveralls.io/repos/stormpath/stormpath-rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/stormpath/stormpath-rails?branch=master)
[![Code Climate](https://codeclimate.com/github/stormpath/stormpath-rails/badges/gpa.svg)](https://codeclimate.com/github/stormpath/stormpath-rails)

# Stormpath Rails
Expand Down Expand Up @@ -38,16 +37,16 @@ rails generate stormpath:install

Create a Stormpath account if you haven't already, and be sure to set up the following environment variables:

- STORMPATH_API_KEY_ID
- STORMPATH_API_KEY_SECRET
- STORMPATH_CLIENT_APIKEY_ID
- STORMPATH_CLIENT_APIKEY_SECRET

Environment variables should be set up in you .bashrc file (or .zshrc if you use myzsh).

Example setup:

```sh
export STORMPATH_API_KEY_ID=6U4HZMHGVHN0U765BGW
export STORMPATH_API_KEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
export STORMPATH_CLIENT_APIKEY_ID=6U4HZMHGVHN0U765BGW
export STORMPATH_CLIENT_APIKEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
```

Alternatively you can use gems such as [Dotenv](https://github.com/bkeepers/dotenv) or [Figaro](https://github.com/laserlemon/figaro) to preload environment variables.
Expand Down Expand Up @@ -91,7 +90,7 @@ You can use embedded ruby (ERB) in the configuration file:
```yaml
stormpath:
application:
href: <%= ENV['STORMPATH_APPLICATION_URL'] %>
href: <%= ENV['STORMPATH_APPLICATION_HREF'] %>
```

## Usage
Expand Down Expand Up @@ -298,12 +297,9 @@ If you wish to contribute to the gem, please follow these steps:

1. Create a Stormpath Application.
2. Export the following env variables:
- STORMPATH_API_KEY_ID
- STORMPATH_API_KEY_SECRET
- STORMPATH_CLIENT_APIKEY_ID
- STORMPATH_CLIENT_APIKEY_SECRET
3. Create a Directory and associate it to the app. Make it the default account and group store for the app.
4. Create a Directory With a Verification Workflow and associate it to the app.
5. Export the following env variable:
- STORMPATH_SDK_TEST_DIRECTORY_WITH_VERIFICATION_URL

### Specs

Expand Down
2 changes: 1 addition & 1 deletion app/services/stormpath/rails/token_cookie_setter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def cookie_data
end

def expires
Time.zone.at(JWT.decode(token, ENV['STORMPATH_API_KEY_SECRET']).first['exp'])
Time.zone.at(JWT.decode(token, Stormpath::Rails::Client.client.data_store.api_key.secret).first['exp'])
end

def http_only
Expand Down
12 changes: 6 additions & 6 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ by running the following commands in the shell:

.. code-block:: bash

export STORMPATH_API_KEY_ID=YOUR_ID_HERE
export STORMPATH_API_KEY_SECRET=YOUR_SECRET_HERE
export STORMPATH_APPLICATION_URL=YOUR_APP_HREF
export STORMPATH_CLIENT_APIKEY_ID=YOUR_ID_HERE
export STORMPATH_CLIENT_APIKEY_SECRET=YOUR_SECRET_HERE
export STORMPATH_APPLICATION_HREF=YOUR_APP_HREF

or by using any text editor and adding the environment variables to .bashrc (or .zshrc if you're using ohmyzsh)

Expand All @@ -35,9 +35,9 @@ or by using any text editor and adding the environment variables to .bashrc (or

.. code-block:: bash

set STORMPATH_API_KEY_ID=YOUR_ID_HERE
set STORMPATH_API_KEY_SECRET=YOUR_SECRET_HERE
set STORMPATH_APPLICATION_URL=YOUR_APP_HREF
set STORMPATH_CLIENT_APIKEY_ID=YOUR_ID_HERE
set STORMPATH_CLIENT_APIKEY_SECRET=YOUR_SECRET_HERE
set STORMPATH_APPLICATION_HREF=YOUR_APP_HREF

The examples above show you the 3 mandatory settings you need to configure to
make stormpath-rails work. These settings can be configured via environment
Expand Down
10 changes: 5 additions & 5 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ prompt you to download your key pair.

Once you've downloaded your `apiKey.properties` file, save it and be sure to set up the following environment variables:

- STORMPATH_API_KEY_ID
- STORMPATH_API_KEY_SECRET
- STORMPATH_CLIENT_APIKEY_ID
- STORMPATH_CLIENT_APIKEY_SECRET

Environment variables should be set up in you .bashrc file (or .zshrc if you use myzsh).

Example setup:

.. code-block:: sh

export STORMPATH_API_KEY_ID=6U4HZMHGVHN0U765BGW
export STORMPATH_API_KEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
export STORMPATH_CLIENT_APIKEY_ID=6U4HZMHGVHN0U765BGW
export STORMPATH_CLIENT_APIKEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv

Find Your Stormpath Application
-------------------------------
Expand Down Expand Up @@ -73,7 +73,7 @@ Now that you have your application HREF, make sure to set up another environment

.. code-block:: sh

export STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/24kkU5XOz4tQlZ7sBtPUN6
export STORMPATH_APPLICATION_HREF=https://api.stormpath.com/v1/applications/24kkU5XOz4tQlZ7sBtPUN6


You're ready to bundle Stormpath Rails gem into your project!
Expand Down
2 changes: 2 additions & 0 deletions lib/stormpath/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Rails
autoload :Controller, 'stormpath/rails/controller'
autoload :Version, 'stormpath/rails/version'
autoload :Social, 'stormpath/rails/social'
autoload :ApiKey, 'stormpath/rails/api_key'
autoload :ContentTypeNegotiator, 'stormpath/rails/content_type_negotiator'
autoload :RoutingConstraint, 'stormpath/rails/routing_constraint'
autoload :InvalidSptokenError, 'stormpath/rails/errors/invalid_sptoken_error'
Expand All @@ -23,5 +24,6 @@ module Rails
autoload :NoGithubAuthorizationError, 'stormpath/rails/errors/no_github_authorization_error'
autoload :FacebookAuthCodeExchange, 'stormpath/rails/facebook_auth_code_exchange'
autoload :GithubAuthCodeExchange, 'stormpath/rails/github_auth_code_exchange'
autoload :EnvNamesWarning, 'stormpath/rails/env_names_warning'
end
end
87 changes: 87 additions & 0 deletions lib/stormpath/rails/api_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module Stormpath
module Rails
class ApiKey
TEST_ENV_VARS = {
required: {
STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key',
STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key',
STORMPATH_APPLICATION_HREF: 'The href to your application'
},
deprecated: {
STORMPATH_API_KEY_ID: 'The id from your Stormpath API Key',
STORMPATH_API_KEY_SECRET: 'The secret from your Stormpath API Key',
STORMPATH_APPLICATION_URL: 'The url to your application'
}
}.freeze

def credentials
check_env_variable_names
credentials_from_env_variables
end

private

def check_env_variable_names
unless test_missing_required_env_vars.empty?
show_deprecation_warning unless env_vars_not_set?
end

raise set_up_message if env_vars_not_set?
end

def credentials_from_env_variables
{
id: ENV['STORMPATH_CLIENT_APIKEY_ID'] || ENV['STORMPATH_API_KEY_ID'],
secret: ENV['STORMPATH_CLIENT_APIKEY_SECRET'] || ENV['STORMPATH_API_KEY_SECRET']
}
end

def test_missing_deprecated_env_vars
TEST_ENV_VARS[:deprecated].reject do |var, _|
ENV[var.to_s]
end
end

def test_missing_required_env_vars
TEST_ENV_VARS[:required].reject do |var, _|
ENV[var.to_s]
end
end

def env_vars_not_set?
!test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty?
end

def show_deprecation_warning
warn deprecation_warning
end

def deprecation_warning
warn_message = "\n\n"
40.times { warn_message << '*' }
warn_message << 'STORMPATH RAILS'
52.times { warn_message << '*' }
warn_message << "\n\n"
warn_message << TEST_ENV_VARS[:deprecated].map do |var, _|
"\t#{var} is deprecated since the new version of the gem."
end.join("\n")
warn_message << "\n\tPlease update your environment variables to use the new names:\n"
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id"
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret"
warn_message << "\n\t\texport STORMPATH_APPLICATION_HREF=href_to_application\n\n"
110.times { warn_message << '*' }
warn_message << "\n\n"
warn_message
end

def set_up_message
set_up_message = "In order to use the stormpath-rails gem you need to set the following environment variables:\n\t"
set_up_message << test_missing_required_env_vars.map do |var, message|
"#{var} : #{message}"
end.join("\n\t")
set_up_message << "\nBe sure to configure these before trying to run your application.\n\n"
set_up_message
end
end
end
end
11 changes: 5 additions & 6 deletions lib/stormpath/rails/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ def self.application
end

def self.client
self.connection ||= Stormpath::Client.new(
api_key: {
id: ENV['STORMPATH_API_KEY_ID'],
secret: ENV['STORMPATH_API_KEY_SECRET']
}
)
self.connection ||= Stormpath::Client.new(api_key: api_key.credentials)
end

def self.api_key
Stormpath::Rails::ApiKey.new
end
end
end
Expand Down
62 changes: 62 additions & 0 deletions lib/stormpath/rails/env_names_warning.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Stormpath
module Rails
module EnvNamesWarning
TEST_ENV_VARS = {
required: {
STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key',
STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key',
STORMPATH_APPLICATION_HREF: 'The href to your application'
},
deprecated: {
STORMPATH_API_KEY_ID: 'The id from your Stormpath API Key',
STORMPATH_API_KEY_SECRET: 'The secret from your Stormpath API Key',
STORMPATH_APPLICATION_URL: 'The url to your application'
}
}.freeze

def self.test_missing_deprecated_env_vars
TEST_ENV_VARS[:deprecated].reject do |var, _|
ENV[var.to_s]
end
end

def self.test_missing_required_env_vars
TEST_ENV_VARS[:required].reject do |var, _|
ENV[var.to_s]
end
end

def self.env_vars_not_set?
!test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty?
end

def self.check_env_variable_names
unless Stormpath::Rails::EnvNamesWarning.test_missing_required_env_vars.empty?
warn_message = "\n\n"
40.times { warn_message << '*' }
warn_message << 'STORMPATH RAILS'
52.times { warn_message << '*' }
warn_message << "\n\n"
warn_message << TEST_ENV_VARS[:deprecated].map do |var, _|
"\t#{var} is deprecated since the new version of the gem."
end.join("\n")
warn_message << "\n\tPlease update your environment variables to use the new names:\n"
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id"
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret"
warn_message << "\n\t\texport STORMPATH_APPLICATION_HREF=href_to_application\n\n"
110.times { warn_message << '*' }
warn "#{warn_message}\n\n" unless Stormpath::Rails::EnvNamesWarning.env_vars_not_set?
end

if Stormpath::Rails::EnvNamesWarning.env_vars_not_set?
set_up_message = "In order to use the stormpath-rails gem you need to set the following environment variables:\n\t"
set_up_message << Stormpath::Rails::EnvNamesWarning.test_missing_required_env_vars.map do |var, message|
"#{var} : #{message}"
end.join("\n\t")
set_up_message << "\nBe sure to configure these before trying to run your application.\n\n"
raise set_up_message
end
end
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module Stormpath
  module Rails
    class ApiKey
      TEST_ENV_VARS = {
        required: {
          STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key',
          STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key',
          STORMPATH_APPLICATION_HREF: 'The href to your application'
        },
        deprecated: {
          STORMPATH_API_KEY_ID: 'The id from your Stormpath API Key',
          STORMPATH_API_KEY_SECRET: 'The secret from your Stormpath API Key',
          STORMPATH_APPLICATION_URL: 'The url to your application'
        }
      }.freeze

      def credentials
        check_env_variable_names
        credentials_from_env_variables
      end

      private

      def check_env_variable_names
        show_deprecation_warning unless test_missing_required_env_vars.empty? && env_vars_not_set?

        raise set_up_message if env_vars_not_set?
      end

      def credentials_from_env_variables
        {
          id: ENV['STORMPATH_CLIENT_APIKEY_ID'] || ENV['STORMPATH_API_KEY_ID'],
          secret: ENV['STORMPATH_CLIENT_APIKEY_SECRET'] || ENV['STORMPATH_API_KEY_SECRET']
        }
      end

      def test_missing_deprecated_env_vars
        TEST_ENV_VARS[:deprecated].reject do |var, _|
          ENV[var.to_s]
        end
      end

      def test_missing_required_env_vars
        TEST_ENV_VARS[:required].reject do |var, _|
          ENV[var.to_s]
        end
      end

      def env_vars_not_set?
        !test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty?
      end

      def show_deprecation_warning
        warn deprecation_warning
      end

      def deprecation_warning
        warn_message = "\n\n"
        40.times { warn_message << '*' }
        warn_message << 'STORMPATH RAILS'
        52.times { warn_message << '*' }
        warn_message << "\n\n"
        warn_message << TEST_ENV_VARS[:deprecated].map do |var, _|
          "\t#{var} is deprecated since the new version of the gem."
        end.join("\n")
        warn_message << "\n\tPlease update your environment variables to use the new names:\n"
        warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id"
        warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret"
        warn_message << "\n\t\texport STORMPATH_APPLICATION_HREF=href_to_application\n\n"
        110.times { warn_message << '*' }
        warn_message << "\n\n"
        warn_message
      end

      def set_up_message
        set_up_message = "In order to use the stormpath-rails gem you need to set the following environment variables:\n\t"
        set_up_message << test_missing_required_env_vars.map do |var, message|
          "#{var} : #{message}"
        end.join("\n\t")
        set_up_message << "\nBe sure to configure these before trying to run your application.\n\n"
        set_up_message
      end

    end
  end
end

2 changes: 1 addition & 1 deletion spec/dummy/config/stormpath.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
stormpath:
application:
href: <%= ENV['STORMPATH_APPLICATION_URL'] %>
href: <%= ENV['STORMPATH_APPLICATION_HREF'] || ENV['STORMPATH_APPLICATION_URL'] %>
name: null

web:
Expand Down
19 changes: 9 additions & 10 deletions spec/features/email_verification_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
require 'spec_helper'

describe 'the email verification feature', type: :feature, vcr: true do
let(:verify_email_config) { configuration.web.verify_email }

let(:application) { test_application }
let(:test_dir_with_verification) do
Stormpath::Rails::Client.client.directories.get(
ENV.fetch('STORMPATH_SDK_TEST_DIRECTORY_WITH_VERIFICATION_URL')
)
Stormpath::Rails::Client.client.directories.create(FactoryGirl.attributes_for(:directory))
end

let(:account) { test_dir_with_verification.accounts.create(account_attrs) }

let(:account_attrs) { FactoryGirl.attributes_for(:account) }

let(:sptoken) { account.email_verification_token.token }

before do
account
enable_email_verification_for(test_dir_with_verification)
map_account_store(application, test_dir_with_verification, 2, false, false)
enable_email_verification
Rails.application.reload_routes!
account
end

after { account.delete }
after do
test_dir_with_verification.delete
account.delete
end

describe 'GET /verify' do
describe 'with no sptoken' do
Expand Down
Loading