omniauth-applicaster 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/README.md +71 -7
- data/lib/applicaster/accounts.rb +65 -3
- data/lib/applicaster/accounts/account.rb +13 -0
- data/lib/applicaster/accounts/user.rb +18 -0
- data/lib/applicaster/auth_helpers.rb +13 -19
- data/lib/applicaster/sessions_controller_mixin.rb +3 -12
- data/lib/omniauth-applicaster/version.rb +1 -1
- data/omniauth-applicaster.gemspec +6 -0
- data/spec/lib/applicaster/accounts/account_spec.rb +3 -0
- data/spec/lib/applicaster/accounts_spec.rb +145 -0
- data/spec/lib/applicaster/auth_helpers_spec.rb +118 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/dummy_controller.rb +15 -0
- data/spec/support/setup_env_vars.rb +2 -0
- data/spec/support/webmock_stubs_helper.rb +21 -0
- metadata +90 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfb4391ae209e39c4f8696aa9739272c001d869b
|
4
|
+
data.tar.gz: e1bacf27810817e764814c017987dfda3c2c06b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58764a8664b29e35dc140db06f17777fe3c813ef961b6033d8239c1723ec4cbc7b394f1dd89b0ca3bbaca5ceb74d9f521266575638692dd4bfe68b027b1502ce
|
7
|
+
data.tar.gz: 955089493db46cba1ae86a5b59849ede304c9ea12b43a4c4cc5e504187fe7cd47f86976badf489b8963910645e1352f525a5d7f86a2fd186b139754dbf6bb92e
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Omniauth::Applicaster
|
2
2
|
|
3
|
-
|
3
|
+
An omniauth strategy for Applicaster's OAuth2 provider and an SDK for the
|
4
|
+
Accounts service.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -10,17 +11,80 @@ Add this line to your application's Gemfile:
|
|
10
11
|
gem 'omniauth-applicaster'
|
11
12
|
```
|
12
13
|
|
13
|
-
|
14
|
+
## Usage
|
14
15
|
|
15
|
-
|
16
|
+
### Configuration
|
16
17
|
|
17
|
-
|
18
|
+
The OAuth client ID and client secret are read from the environment variables
|
19
|
+
`ACCOUNTS_CLIENT_ID` and `ACCOUNTS_CLIENT_SECRET` respectivly.
|
18
20
|
|
19
|
-
|
21
|
+
The gem uses `https://accounts2.applicaster.com` as the site's endpoint by
|
22
|
+
default to change this set the `ACCOUNTS_BASE_URL` environment variable. This is
|
23
|
+
useful for example when running a local version of the accounts service
|
20
24
|
|
21
|
-
|
25
|
+
### Omniauth strategy
|
26
|
+
|
27
|
+
See [Omniauth](https://github.com/intridea/omniauth) for setting up omniauth.
|
28
|
+
|
29
|
+
In Rails, you will need something along the lines of:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
ENV["ACCOUNTS_CLIENT_ID"] = "my-service-uid"
|
33
|
+
ENV["ACCOUNTS_CLIENT_SECRET"] = "my-service-secret"
|
34
|
+
|
35
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
36
|
+
provider :applicaster,
|
37
|
+
ENV["ACCOUNTS_CLIENT_ID"],
|
38
|
+
ENV["ACCOUNTS_CLIENT_SECRET"]
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
In addition, the gem provides `Applicaster::AuthHelpers` and
|
43
|
+
`Applicaster::SessionsControllerMixin` for easy integration with Rails
|
44
|
+
projects.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class ApplicationController < ActionController::Base
|
48
|
+
include Applicaster::AuthHelpers
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class SessionsController < ApplicationController
|
54
|
+
include Applicaster::SessionsControllerMixin
|
55
|
+
end
|
56
|
+
```
|
22
57
|
|
23
|
-
|
58
|
+
In your `routes.rb` you need to add:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
MyApp::Application.routes.draw do
|
62
|
+
get "/login", to: "sessions#new", as: :login
|
63
|
+
delete "/logout", to: "sessions#destroy", as: :logout
|
64
|
+
|
65
|
+
get "/auth/:provider/callback", to: "sessions#create"
|
66
|
+
get "/auth/failure", to: "sessions#failure"
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
### Accounts SDK
|
71
|
+
|
72
|
+
#### List all available accounts
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
service = Applicaster::Accounts.new
|
76
|
+
|
77
|
+
service.accounts.each do |account|
|
78
|
+
# account is an Applicaster::Accounts::Account instance
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
#### Get a user using an access token
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
user = Applicaster::Accounts.user_from_token(access_token)
|
86
|
+
# user is an Applicaster::Accounts::User instnce
|
87
|
+
```
|
24
88
|
|
25
89
|
## Contributing
|
26
90
|
|
data/lib/applicaster/accounts.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "virtus"
|
4
|
+
|
1
5
|
module Applicaster
|
2
6
|
class Accounts
|
7
|
+
autoload :Account, "applicaster/accounts/account"
|
8
|
+
autoload :User, "applicaster/accounts/user"
|
9
|
+
|
10
|
+
RETRYABLE_STATUS_CODES = [500, 503, 502]
|
11
|
+
FARADAY_TIMEOUT = 0.5
|
12
|
+
|
3
13
|
attr_accessor :client_id
|
4
14
|
attr_accessor :client_secret
|
5
15
|
|
@@ -11,17 +21,69 @@ module Applicaster
|
|
11
21
|
def site
|
12
22
|
URI.parse(ENV["ACCOUNTS_BASE_URL"] || default_site)
|
13
23
|
end
|
24
|
+
|
25
|
+
def connection(options = {})
|
26
|
+
Faraday.new(url: site, request: { timeout: FARADAY_TIMEOUT } ) do |conn|
|
27
|
+
if options[:token]
|
28
|
+
conn.request :oauth2, options[:token]
|
29
|
+
end
|
30
|
+
|
31
|
+
conn.request :json
|
32
|
+
conn.request :retry,
|
33
|
+
interval: 0.05,
|
34
|
+
backoff_factor: 2,
|
35
|
+
exceptions: [Faraday::ClientError, Faraday::TimeoutError],
|
36
|
+
methods: [],
|
37
|
+
retry_if: -> (env, exception) {
|
38
|
+
env[:method] == :get &&
|
39
|
+
RETRYABLE_STATUS_CODES.include?(env[:status])
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
conn.response :json, content_type: /\bjson$/
|
44
|
+
# conn.response :logger, Rails.logger
|
45
|
+
# conn.response :logger, Logger.new(STDOUT)
|
46
|
+
conn.response :raise_error
|
47
|
+
|
48
|
+
conn.adapter Faraday.default_adapter
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_from_token(token)
|
53
|
+
Applicaster::Accounts::User.new(
|
54
|
+
connection(token: token)
|
55
|
+
.get("/api/v1/users/current.json")
|
56
|
+
.body
|
57
|
+
)
|
58
|
+
end
|
14
59
|
end
|
15
60
|
|
16
|
-
def initialize(client_id, client_secret)
|
17
|
-
@client_id = client_id
|
18
|
-
@client_secret = client_secret
|
61
|
+
def initialize(client_id = nil, client_secret = nil)
|
62
|
+
@client_id = client_id || ENV["ACCOUNTS_CLIENT_ID"]
|
63
|
+
@client_secret = client_secret || ENV["ACCOUNTS_CLIENT_SECRET"]
|
19
64
|
end
|
20
65
|
|
21
66
|
def user_data_from_omniauth(omniauth_credentials)
|
22
67
|
access_token(omniauth_credentials).get("/api/v1/users/current.json").parsed
|
23
68
|
end
|
24
69
|
|
70
|
+
def accounts
|
71
|
+
connection(token: client_credentials_token.token)
|
72
|
+
.get("/api/v1/accounts.json")
|
73
|
+
.body
|
74
|
+
.map {|a| Account.new(a) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def connection(*args)
|
78
|
+
self.class.connection(*args)
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
def client_credentials_token
|
84
|
+
@client_credentials_token ||= client.client_credentials.get_token
|
85
|
+
end
|
86
|
+
|
25
87
|
def client
|
26
88
|
@client ||= ::OAuth2::Client.new(
|
27
89
|
client_id,
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Applicaster
|
2
|
+
class Accounts
|
3
|
+
class User
|
4
|
+
include Virtus.model
|
5
|
+
|
6
|
+
attribute :id, String
|
7
|
+
attribute :name, String
|
8
|
+
attribute :email, String
|
9
|
+
attribute :global_roles, Array[String]
|
10
|
+
attribute :permissions, Array
|
11
|
+
attribute :admin, Boolean
|
12
|
+
|
13
|
+
def admin?
|
14
|
+
!!admin
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -3,22 +3,13 @@ require_relative "user"
|
|
3
3
|
module Applicaster
|
4
4
|
module AuthHelpers
|
5
5
|
def current_user
|
6
|
-
|
7
|
-
|
8
|
-
@current_user ||= user_from_session.tap do |user|
|
9
|
-
session.delete(:omniauth_credentials) unless user
|
10
|
-
end
|
11
|
-
rescue OAuth2::Error => e
|
12
|
-
session.delete(:omniauth_credentials)
|
13
|
-
nil
|
6
|
+
@current_user ||= user_from_session
|
14
7
|
end
|
15
8
|
|
16
9
|
def user_signed_in?
|
17
10
|
!current_user.nil?
|
18
11
|
end
|
19
12
|
|
20
|
-
protected
|
21
|
-
|
22
13
|
def authenticate_user!
|
23
14
|
unless current_user
|
24
15
|
session[:path_before_login] = url_for(params)
|
@@ -26,17 +17,20 @@ module Applicaster
|
|
26
17
|
end
|
27
18
|
end
|
28
19
|
|
20
|
+
protected
|
21
|
+
|
29
22
|
def user_from_session
|
30
|
-
|
31
|
-
accounts_client.user_data_from_omniauth(session[:omniauth_credentials])
|
32
|
-
)
|
33
|
-
end
|
23
|
+
return nil unless session[:omniauth_credentials]
|
34
24
|
|
35
|
-
|
36
|
-
Applicaster::Accounts.
|
37
|
-
|
38
|
-
|
39
|
-
|
25
|
+
token = session[:omniauth_credentials][:token]
|
26
|
+
Applicaster::Accounts.user_from_token(token)
|
27
|
+
rescue Faraday::ClientError => e
|
28
|
+
if e.response[:status] == 401
|
29
|
+
session.delete(:omniauth_credentials)
|
30
|
+
nil
|
31
|
+
else
|
32
|
+
raise e
|
33
|
+
end
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
@@ -5,7 +5,7 @@ module Applicaster
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def create
|
8
|
-
session[:omniauth_credentials] =
|
8
|
+
session[:omniauth_credentials] = omniauth_credentials
|
9
9
|
|
10
10
|
redirect_to(session.delete(:path_before_login) || '/')
|
11
11
|
end
|
@@ -27,17 +27,8 @@ module Applicaster
|
|
27
27
|
|
28
28
|
protected
|
29
29
|
|
30
|
-
def
|
31
|
-
request.env['omniauth.auth']
|
30
|
+
def omniauth_credentials
|
31
|
+
request.env['omniauth.auth'].credentials.to_hash.symbolize_keys
|
32
32
|
end
|
33
|
-
|
34
|
-
def access_token
|
35
|
-
@access_token ||= OAuth2::AccessToken.new(
|
36
|
-
client,
|
37
|
-
auth_hash.credentials.token,
|
38
|
-
auth_hash.credentials.to_hash.except("token", "expires"),
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
33
|
end
|
43
34
|
end
|
@@ -20,5 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
|
23
26
|
spec.add_dependency "omniauth-oauth2"
|
27
|
+
spec.add_dependency "faraday", "~> 0.9.1"
|
28
|
+
spec.add_dependency "faraday_middleware"
|
29
|
+
spec.add_dependency "virtus"
|
24
30
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
RSpec.describe Applicaster::Accounts do
|
2
|
+
let(:accounts_service) { Applicaster::Accounts.new }
|
3
|
+
|
4
|
+
describe "::RETRYABLE_STATUS_CODES" do
|
5
|
+
it "is [500, 503, 502]" do
|
6
|
+
expect(Applicaster::Accounts::RETRYABLE_STATUS_CODES).to eq([500, 503, 502])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".site" do
|
11
|
+
it "returns a URI object" do
|
12
|
+
expect(return_value).to be_kind_of(URI)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns https://accounts2.applicaster.com" do
|
16
|
+
expect(return_value.to_s).to eq("https://accounts2.applicaster.com")
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when ACCOUNTS_BASE_URL is set" do
|
20
|
+
around do |example|
|
21
|
+
with_base_url("http://example.com") do
|
22
|
+
example.run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns http://example.com" do
|
27
|
+
expect(return_value.to_s).to eq("http://example.com")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def return_value
|
32
|
+
Applicaster::Accounts.site
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#initialize" do
|
37
|
+
it "accepts client_id and client_secret" do
|
38
|
+
service = Applicaster::Accounts.new("my_client_id", "my_client_secret")
|
39
|
+
|
40
|
+
expect(service.client_id).to eq("my_client_id")
|
41
|
+
expect(service.client_secret).to eq("my_client_secret")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "takes default values from ENV vars" do
|
45
|
+
expect(accounts_service.client_id).to eq("client_id")
|
46
|
+
expect(accounts_service.client_secret).to eq("client_secret")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#accounts" do
|
51
|
+
before do
|
52
|
+
stub_client_credentials_request
|
53
|
+
stub_accounts_index_request
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns an array of Account objects" do
|
57
|
+
expect(return_value).to be_kind_of(Array)
|
58
|
+
expect(return_value.size).to eq(2)
|
59
|
+
expect(return_value.first).to be_kind_of(Applicaster::Accounts::Account)
|
60
|
+
end
|
61
|
+
|
62
|
+
def return_value
|
63
|
+
@return_value ||= accounts_service.accounts
|
64
|
+
end
|
65
|
+
|
66
|
+
def stub_accounts_index_request
|
67
|
+
stub_request(:get, "https://accounts2.applicaster.com/api/v1/accounts.json").
|
68
|
+
with(query: { access_token: "client-credentials-token" }).
|
69
|
+
to_return(successful_json_response(mock_accounts_response))
|
70
|
+
end
|
71
|
+
|
72
|
+
def mock_accounts_response
|
73
|
+
[
|
74
|
+
{
|
75
|
+
id: "1-account-1",
|
76
|
+
name: "Account 1",
|
77
|
+
},
|
78
|
+
{
|
79
|
+
id: "2-account-2",
|
80
|
+
name: "Account 2",
|
81
|
+
},
|
82
|
+
]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe ".connection" do
|
87
|
+
let(:remote_url) { "https://accounts2.applicaster.com/test.json" }
|
88
|
+
let(:request_stub) { stub_request(:get, remote_url) }
|
89
|
+
|
90
|
+
context "with successful response" do
|
91
|
+
before do
|
92
|
+
request_stub
|
93
|
+
.to_return(successful_json_response({key: "val"}))
|
94
|
+
end
|
95
|
+
|
96
|
+
it "encodes JSON" do
|
97
|
+
expect(connection.get("/test.json").body).to eq("key" => "val")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when server responds with 503" do
|
102
|
+
before do
|
103
|
+
request_stub
|
104
|
+
.to_return(status: 503, body: "")
|
105
|
+
.to_return(successful_json_response({}))
|
106
|
+
end
|
107
|
+
|
108
|
+
it "retries the request" do
|
109
|
+
connection.get("/test.json")
|
110
|
+
|
111
|
+
expect(request_stub).to have_been_requested.twice
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when server is not responding" do
|
116
|
+
around do |example|
|
117
|
+
with_base_url("http://localhost:6969") do
|
118
|
+
WebMock.allow_net_connect!
|
119
|
+
example.run
|
120
|
+
WebMock.disable_net_connect!
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
before do
|
125
|
+
@server = TCPServer.new(6969)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "times out after 0.5 second with 2 retries" do
|
129
|
+
expect {
|
130
|
+
connection.get("/test.json") rescue nil
|
131
|
+
}.to change { Time.now }.by(a_value < 1.5)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def connection
|
136
|
+
Applicaster::Accounts.connection
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def with_base_url(url)
|
141
|
+
value_bofre, ENV["ACCOUNTS_BASE_URL"] = ENV["ACCOUNTS_BASE_URL"], url
|
142
|
+
yield
|
143
|
+
ENV["ACCOUNTS_BASE_URL"] = value_bofre
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
RSpec.describe Applicaster::AuthHelpers do
|
2
|
+
let(:dummy_class) { Class.new(DummyController) { include Applicaster::AuthHelpers } }
|
3
|
+
let(:controller) { dummy_class.new }
|
4
|
+
|
5
|
+
before do
|
6
|
+
allow(controller).to receive(:session).and_return(session)
|
7
|
+
|
8
|
+
stub_current_user_requests
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#current_user" do
|
12
|
+
context "when token in session is valid" do
|
13
|
+
it "returns current_user" do
|
14
|
+
expect(controller.current_user.id).to eq("123")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "memoizes value" do
|
18
|
+
expect(Applicaster::Accounts).to receive(:user_from_token)
|
19
|
+
.once
|
20
|
+
.and_call_original
|
21
|
+
|
22
|
+
controller.current_user
|
23
|
+
controller.current_user
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when token in session is invalid" do
|
28
|
+
it "removes token from session" do
|
29
|
+
controller.current_user
|
30
|
+
|
31
|
+
expect(controller.session).to_not have_key(:omniauth_credentials)
|
32
|
+
end
|
33
|
+
|
34
|
+
def session
|
35
|
+
super.tap do |session|
|
36
|
+
session[:omniauth_credentials][:token] = "invalid-access-token"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#user_signed_in?" do
|
43
|
+
context "when current_user is truthy" do
|
44
|
+
before do
|
45
|
+
allow(controller).to receive(:current_user).and_return({})
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns true" do
|
49
|
+
expect(controller.user_signed_in?).to be true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when current_user is nil" do
|
54
|
+
before do
|
55
|
+
allow(controller).to receive(:current_user).and_return(nil)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns false" do
|
59
|
+
expect(controller.user_signed_in?).to be false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#authenticate_user!" do
|
65
|
+
context "when current_user is truthy" do
|
66
|
+
before do
|
67
|
+
allow(controller).to receive(:current_user).and_return({})
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not redirect" do
|
71
|
+
expect(controller).to_not receive(:redirect_to)
|
72
|
+
controller.authenticate_user!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when current_user is nil" do
|
77
|
+
before do
|
78
|
+
allow(controller).to receive(:current_user).and_return(nil)
|
79
|
+
allow(controller).to receive(:url_for).and_return("/current")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "redirects to '/auth/applicaster'" do
|
83
|
+
expect(controller).to receive(:redirect_to).with("/auth/applicaster")
|
84
|
+
controller.authenticate_user!
|
85
|
+
end
|
86
|
+
|
87
|
+
it "saves the path of the current request" do
|
88
|
+
controller.authenticate_user!
|
89
|
+
|
90
|
+
expect(controller.session[:path_before_login]).to eq("/current")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def session
|
96
|
+
{
|
97
|
+
omniauth_credentials: {
|
98
|
+
token: "valid-access-token"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def stub_current_user_requests
|
104
|
+
stub_request(:get, "https://accounts2.applicaster.com/api/v1/users/current.json")
|
105
|
+
.with(query: { access_token: "valid-access-token" })
|
106
|
+
.to_return(successful_json_response(mock_user_response))
|
107
|
+
|
108
|
+
stub_request(:get, "https://accounts2.applicaster.com/api/v1/users/current.json")
|
109
|
+
.with(query: { access_token: "invalid-access-token" })
|
110
|
+
.to_return(status: 401, body: "")
|
111
|
+
end
|
112
|
+
|
113
|
+
def mock_user_response
|
114
|
+
{
|
115
|
+
id: "123"
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "omniauth-applicaster"
|
2
|
+
require "webmock/rspec"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
|
13
|
+
# These two settings work together to allow you to limit a spec run
|
14
|
+
# to individual examples or groups you care about by tagging them with
|
15
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
16
|
+
# get run.
|
17
|
+
config.filter_run :focus
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
|
20
|
+
config.disable_monkey_patching!
|
21
|
+
|
22
|
+
config.warnings = true
|
23
|
+
|
24
|
+
if config.files_to_run.one?
|
25
|
+
config.default_formatter = 'doc'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Print the 10 slowest examples and example groups at the
|
29
|
+
# end of the spec run, to help surface which specs are running
|
30
|
+
# particularly slow.
|
31
|
+
# config.profile_examples = 10
|
32
|
+
|
33
|
+
config.order = :random
|
34
|
+
Kernel.srand config.seed
|
35
|
+
|
36
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")]
|
37
|
+
.each { |f| require f }
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WebmockStubsHelper
|
2
|
+
RSpec.configure do |config|
|
3
|
+
config.include self
|
4
|
+
end
|
5
|
+
|
6
|
+
def stub_client_credentials_request
|
7
|
+
stub_request(:post, "https://client_id:client_secret@accounts2.applicaster.com/oauth/token").
|
8
|
+
with(:body => {"grant_type"=>"client_credentials"}).
|
9
|
+
to_return(successful_json_response(access_token: "client-credentials-token"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def successful_json_response(body)
|
13
|
+
{
|
14
|
+
status: 200,
|
15
|
+
body: body.to_json,
|
16
|
+
headers: {
|
17
|
+
"Content-Type" => "application/json"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-applicaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neer Friedman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: omniauth-oauth2
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +80,48 @@ dependencies:
|
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: virtus
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
55
125
|
description: Omniauth strategy for http://accounts.applicaster.com
|
56
126
|
email:
|
57
127
|
- neerfri@gmail.com
|
@@ -60,11 +130,14 @@ extensions: []
|
|
60
130
|
extra_rdoc_files: []
|
61
131
|
files:
|
62
132
|
- ".gitignore"
|
133
|
+
- ".rspec"
|
63
134
|
- Gemfile
|
64
135
|
- LICENSE.txt
|
65
136
|
- README.md
|
66
137
|
- Rakefile
|
67
138
|
- lib/applicaster/accounts.rb
|
139
|
+
- lib/applicaster/accounts/account.rb
|
140
|
+
- lib/applicaster/accounts/user.rb
|
68
141
|
- lib/applicaster/auth_helpers.rb
|
69
142
|
- lib/applicaster/sessions_controller_mixin.rb
|
70
143
|
- lib/applicaster/user.rb
|
@@ -72,6 +145,13 @@ files:
|
|
72
145
|
- lib/omniauth-applicaster/version.rb
|
73
146
|
- lib/omniauth/strategies/applicaster.rb
|
74
147
|
- omniauth-applicaster.gemspec
|
148
|
+
- spec/lib/applicaster/accounts/account_spec.rb
|
149
|
+
- spec/lib/applicaster/accounts_spec.rb
|
150
|
+
- spec/lib/applicaster/auth_helpers_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/support/dummy_controller.rb
|
153
|
+
- spec/support/setup_env_vars.rb
|
154
|
+
- spec/support/webmock_stubs_helper.rb
|
75
155
|
homepage: ''
|
76
156
|
licenses:
|
77
157
|
- MIT
|
@@ -96,4 +176,11 @@ rubygems_version: 2.2.2
|
|
96
176
|
signing_key:
|
97
177
|
specification_version: 4
|
98
178
|
summary: Omniauth strategy for http://accounts.applicaster.com
|
99
|
-
test_files:
|
179
|
+
test_files:
|
180
|
+
- spec/lib/applicaster/accounts/account_spec.rb
|
181
|
+
- spec/lib/applicaster/accounts_spec.rb
|
182
|
+
- spec/lib/applicaster/auth_helpers_spec.rb
|
183
|
+
- spec/spec_helper.rb
|
184
|
+
- spec/support/dummy_controller.rb
|
185
|
+
- spec/support/setup_env_vars.rb
|
186
|
+
- spec/support/webmock_stubs_helper.rb
|