auth-transis-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +41 -0
- data/auth-transis-client.gemspec +2 -0
- data/lib/auth-transis-client.rb +57 -2
- data/lib/auth-transis-client/version.rb +2 -2
- data/lib/omni_auth.rb +4 -0
- metadata +35 -2
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
auth-transis-client (0.0.3)
|
5
|
+
faraday
|
6
|
+
faraday_middleware
|
7
|
+
omniauth
|
8
|
+
omniauth-oauth2
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
faraday (0.8.4)
|
14
|
+
multipart-post (~> 1.1)
|
15
|
+
faraday_middleware (0.8.8)
|
16
|
+
faraday (>= 0.7.4, < 0.9)
|
17
|
+
hashie (1.2.0)
|
18
|
+
httpauth (0.1)
|
19
|
+
jwt (0.1.5)
|
20
|
+
multi_json (>= 1.0)
|
21
|
+
multi_json (1.3.6)
|
22
|
+
multipart-post (1.1.5)
|
23
|
+
oauth2 (0.8.0)
|
24
|
+
faraday (~> 0.8)
|
25
|
+
httpauth (~> 0.1)
|
26
|
+
jwt (~> 0.1.4)
|
27
|
+
multi_json (~> 1.0)
|
28
|
+
rack (~> 1.2)
|
29
|
+
omniauth (1.1.0)
|
30
|
+
hashie (~> 1.2)
|
31
|
+
rack
|
32
|
+
omniauth-oauth2 (1.1.0)
|
33
|
+
oauth2 (~> 0.8.0)
|
34
|
+
omniauth (~> 1.0)
|
35
|
+
rack (1.4.1)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
auth-transis-client!
|
data/auth-transis-client.gemspec
CHANGED
data/lib/auth-transis-client.rb
CHANGED
@@ -2,11 +2,66 @@ require "auth-transis-client/version"
|
|
2
2
|
require 'omniauth'
|
3
3
|
require 'omniauth-oauth2'
|
4
4
|
require "omni_auth"
|
5
|
+
require 'faraday_middleware'
|
5
6
|
|
6
7
|
module Auth
|
7
8
|
module Transis
|
8
|
-
|
9
|
-
|
9
|
+
class Client
|
10
|
+
def initialize(opts={})
|
11
|
+
fill_in_access_token!(opts)
|
12
|
+
if opts[:site] && opts[:token]
|
13
|
+
@connection = Faraday.new opts[:site] do |conn|
|
14
|
+
conn.request :oauth2, opts[:token]
|
15
|
+
conn.request :json
|
16
|
+
|
17
|
+
conn.response :json, :content_type => /\bjson$/
|
18
|
+
|
19
|
+
conn.use :instrumentation
|
20
|
+
conn.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise <<-ERROR
|
24
|
+
Either provide :token or provide :site, :username, :password, :client_id, and :client_secret
|
25
|
+
ERROR
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def fill_in_access_token!(opts)
|
30
|
+
return if opts[:token]
|
31
|
+
return unless opts[:site] && opts[:username] && opts[:client_id] && opts[:client_secret]
|
32
|
+
connection = Faraday.new opts[:site] do |conn|
|
33
|
+
conn.request :json
|
34
|
+
conn.response :json, :content_type => /\bjson$/
|
35
|
+
conn.use :instrumentation
|
36
|
+
conn.adapter Faraday.default_adapter
|
37
|
+
end
|
38
|
+
response = connection.post('/oauth/token',
|
39
|
+
:grant_type => 'password',
|
40
|
+
:client_id => opts[:client_id],
|
41
|
+
:client_secret => opts[:client_secret],
|
42
|
+
:username => opts[:username],
|
43
|
+
:password => opts[:password])
|
44
|
+
raise 'Failed to get an access token' unless response.success? && response.body['access_token']
|
45
|
+
opts[:token] = response.body['access_token']
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_credentials
|
49
|
+
@connection.get('/api/v1/me.json').body
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_organizations(user_id=nil)
|
53
|
+
options = {}
|
54
|
+
options[:user_id]=user_id if user_id
|
55
|
+
@connection.get('/api/v1/organizations.json', options).body
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_members_of_organization(organization_id)
|
59
|
+
@connection.get("/api/v1/organizations/#{organization_id}/members.json").body
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_member_to_organization(organization_id, email_address)
|
63
|
+
@connection.post("/api/v1/organizations/#{organization_id}/members.json", :email=>email_address)
|
64
|
+
end
|
10
65
|
end
|
11
66
|
end
|
12
67
|
end
|
data/lib/omni_auth.rb
CHANGED
@@ -17,6 +17,10 @@ module OmniAuth
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
+
def request_phase
|
21
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params).merge(request.params))
|
22
|
+
end
|
23
|
+
|
20
24
|
def raw_info
|
21
25
|
@raw_info ||= access_token.get('/api/v1/me.json').parsed
|
22
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth-transis-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faraday
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: faraday_middleware
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: This is the client for TransisApps
|
47
79
|
email:
|
48
80
|
- tim@galeckas.com
|
@@ -52,6 +84,7 @@ extra_rdoc_files: []
|
|
52
84
|
files:
|
53
85
|
- .gitignore
|
54
86
|
- Gemfile
|
87
|
+
- Gemfile.lock
|
55
88
|
- LICENSE.txt
|
56
89
|
- README.md
|
57
90
|
- Rakefile
|