oauth2-client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OAuth2::Grant::DeviceCode do
4
+
5
+ before :all do
6
+ @host = 'example.com'
7
+ @client_id = 's6BhdRkqt3'
8
+ @client_secret = 'SplxlOBeZQQYbYS6WxSbIA'
9
+ @client = OAuth2::Client.new(@host, @client_id, @client_secret)
10
+ end
11
+
12
+ subject do
13
+ OAuth2::Grant::DeviceCode.new(@client)
14
+ end
15
+
16
+ describe "#grant_type" do
17
+ it "returns grant type" do
18
+ expect(subject.grant_type).to eq 'http://oauth.net/grant_type/device/1.0'
19
+ end
20
+ end
21
+
22
+ describe "#get_code" do
23
+ it "gets user code" do
24
+ subject.should_receive(:make_request).with(:post, "/oauth2/device/code", {:params=>{:client_id=>"s6BhdRkqt3"}})
25
+ subject.get_code
26
+ end
27
+ end
28
+
29
+ describe "#get_token" do
30
+ it "gets access token" do
31
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:code=>"G3Y6jU3a", :grant_type=>"http://oauth.net/grant_type/device/1.0"}, :authenticate=>:headers})
32
+ subject.get_token('G3Y6jU3a')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OAuth2::Grant::Implicit do
4
+
5
+ before :all do
6
+ @host = 'example.com'
7
+ @client_id = 's6BhdRkqt3'
8
+ @client_secret = 'SplxlOBeZQQYbYS6WxSbIA'
9
+ @client = OAuth2::Client.new(@host, @client_id, @client_secret)
10
+ end
11
+
12
+ subject do
13
+ OAuth2::Grant::Implicit.new(@client)
14
+ end
15
+
16
+ describe "#response_type" do
17
+ it "returns response type" do
18
+ expect(subject.response_type).to eq 'token'
19
+ end
20
+ end
21
+
22
+ describe "#token_url" do
23
+ it "generates a token path using the given parameters" do
24
+ path = subject.token_url(:scope => 'xyz', :state => 'abc xyz')
25
+ query_values = Addressable::URI.parse(path).query_values
26
+ expect(query_values).to eq({"scope"=>"xyz", "state"=>"abc xyz", "response_type"=>"token", "client_id"=>"s6BhdRkqt3"})
27
+ end
28
+ end
29
+
30
+ describe "#get_token" do
31
+ it "gets access token" do
32
+ subject.should_receive(:make_request).with(:get, "/oauth2/token", {:params=>{:scope=>"xyz", :state=>"abc xyz", :response_type=>"token", :client_id=>"s6BhdRkqt3"}, :authenticate=>:headers})
33
+ subject.get_token(:params => {:scope => 'xyz', :state => 'abc xyz'})
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OAuth2::Grant::Password do
4
+
5
+ before :all do
6
+ @host = 'example.com'
7
+ @client_id = 's6BhdRkqt3'
8
+ @client_secret = 'SplxlOBeZQQYbYS6WxSbIA'
9
+ @client = OAuth2::Client.new(@host, @client_id, @client_secret)
10
+ end
11
+
12
+ subject do
13
+ OAuth2::Grant::Password.new(@client)
14
+ end
15
+
16
+ describe "#grant_type" do
17
+ it "returns grant type" do
18
+ expect(subject.grant_type).to eq 'password'
19
+ end
20
+ end
21
+
22
+ describe "#get_token" do
23
+ it "gets access token" do
24
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:grant_type=>"password", :username=>"benutzername", :password=>"passwort"}, :authenticate=>:headers})
25
+ subject.get_token('benutzername', 'passwort')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OAuth2::Grant::RefreshToken do
4
+
5
+ before :all do
6
+ @host = 'example.com'
7
+ @client_id = 's6BhdRkqt3'
8
+ @client_secret = 'SplxlOBeZQQYbYS6WxSbIA'
9
+ @client = OAuth2::Client.new(@host, @client_id, @client_secret)
10
+ end
11
+ subject do
12
+ OAuth2::Grant::RefreshToken.new(@client)
13
+ end
14
+
15
+ describe "#grant_type" do
16
+ it "returns grant type" do
17
+ expect(subject.grant_type).to eq 'refresh_token'
18
+ end
19
+ end
20
+
21
+ describe "#get_token" do
22
+ it "gets access token" do
23
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:grant_type=>"refresh_token", :refresh_token=>"2YotnFZFEjr1zCsicMWpAA"}, :authenticate=>:headers})
24
+ subject.get_token('2YotnFZFEjr1zCsicMWpAA')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('../../examples', __FILE__)
2
+
3
+ # require 'simplecov'
4
+ # SimpleCov.start
5
+
6
+ require 'rspec'
7
+ require 'rspec/autorun'
8
+ require 'oauth2'
9
+
10
+ RSpec.configure do |config|
11
+ config.mock_with :rspec
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth2-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Mutyaba
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Create quick and dirty OAuth2 clients for many services. Google OAuth2
15
+ client included
16
+ email: tiabasnk@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .travis.yml
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - TODO
29
+ - doc/README
30
+ - examples/google_client.rb
31
+ - lib/oauth2.rb
32
+ - lib/oauth2/client.rb
33
+ - lib/oauth2/connection.rb
34
+ - lib/oauth2/error.rb
35
+ - lib/oauth2/grant.rb
36
+ - lib/oauth2/grant/authorization_code.rb
37
+ - lib/oauth2/grant/base.rb
38
+ - lib/oauth2/grant/client_credentials.rb
39
+ - lib/oauth2/grant/device.rb
40
+ - lib/oauth2/grant/implicit.rb
41
+ - lib/oauth2/grant/password.rb
42
+ - lib/oauth2/grant/refresh_token.rb
43
+ - lib/oauth2/helper.rb
44
+ - lib/oauth2/version.rb
45
+ - oauth2-client.gemspec
46
+ - spec/.DS_Store
47
+ - spec/examples/google_client_spec.rb
48
+ - spec/mocks/oauth_client.yml
49
+ - spec/oauth2/client_spec.rb
50
+ - spec/oauth2/connection_spec.rb
51
+ - spec/oauth2/grant/authorization_code_spec.rb
52
+ - spec/oauth2/grant/base_spec.rb
53
+ - spec/oauth2/grant/client_credentials_spec.rb
54
+ - spec/oauth2/grant/device_spec.rb
55
+ - spec/oauth2/grant/implicit_spec.rb
56
+ - spec/oauth2/grant/password_spec.rb
57
+ - spec/oauth2/grant/refresh_token_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: ''
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.24
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: OAuth2 Ruby Client
83
+ test_files: []