yammer-oauth2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +28 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.md +20 -0
- data/README.md +136 -0
- data/Rakefile +11 -0
- data/certs/tiabas-public.pem +21 -0
- data/lib/yammer-oauth2/client.rb +100 -0
- data/lib/yammer-oauth2/version.rb +11 -0
- data/spec/client_spec.rb +81 -0
- data/spec/spec_helper.rb +38 -0
- data/yammer-oauth2.gemspec +24 -0
- data.tar.gz.sig +4 -0
- metadata +120 -0
- metadata.gz.sig +1 -0
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
# OS generated files #
|
21
|
+
.DS_Store
|
22
|
+
.DS_Store?
|
23
|
+
._*
|
24
|
+
.Spotlight-V100
|
25
|
+
.Trashes
|
26
|
+
Icon?
|
27
|
+
ehthumbs.db
|
28
|
+
Thumbs.db
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yammer-oauth2 (0.1.0)
|
5
|
+
oauth2-client (~> 1.1.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.3)
|
11
|
+
bcrypt-ruby (3.0.1)
|
12
|
+
colorize (0.5.8)
|
13
|
+
coveralls (0.6.0)
|
14
|
+
colorize
|
15
|
+
multi_json (~> 1.3)
|
16
|
+
rest-client
|
17
|
+
simplecov (>= 0.7)
|
18
|
+
thor
|
19
|
+
crack (0.3.2)
|
20
|
+
diff-lcs (1.2.1)
|
21
|
+
json (1.7.7)
|
22
|
+
mime-types (1.21)
|
23
|
+
multi_json (1.6.1)
|
24
|
+
oauth2-client (1.1.2)
|
25
|
+
addressable
|
26
|
+
bcrypt-ruby (~> 3.0.0)
|
27
|
+
rake (10.0.3)
|
28
|
+
rest-client (1.6.7)
|
29
|
+
mime-types (>= 1.16)
|
30
|
+
rspec (2.13.0)
|
31
|
+
rspec-core (~> 2.13.0)
|
32
|
+
rspec-expectations (~> 2.13.0)
|
33
|
+
rspec-mocks (~> 2.13.0)
|
34
|
+
rspec-core (2.13.0)
|
35
|
+
rspec-expectations (2.13.0)
|
36
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
37
|
+
rspec-mocks (2.13.0)
|
38
|
+
simplecov (0.7.1)
|
39
|
+
multi_json (~> 1.0)
|
40
|
+
simplecov-html (~> 0.7.1)
|
41
|
+
simplecov-html (0.7.1)
|
42
|
+
thor (0.17.0)
|
43
|
+
webmock (1.10.1)
|
44
|
+
addressable (>= 2.2.7)
|
45
|
+
crack (>= 0.3.2)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 1.0)
|
52
|
+
coveralls
|
53
|
+
json
|
54
|
+
rake
|
55
|
+
rspec (>= 2.11)
|
56
|
+
simplecov
|
57
|
+
webmock
|
58
|
+
yammer-oauth2!
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013, Kevin Mutyaba
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# OAuth2 Client Ruby
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yammer-oauth2.png)][gem]
|
4
|
+
[![Build Status](https://secure.travis-ci.org/tiabas/yammer-oauth2.png?branch=master)][travis]
|
5
|
+
[![Dependency Status](https://gemnasium.com/tiabas/yammer-oauth2.png)][gemnasium]
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/tiabas/yammer-oauth2/badge.png?branch=master)][coveralls]
|
7
|
+
|
8
|
+
[gem]: https://rubygems.org/gems/yammer-oauth2
|
9
|
+
[travis]: http://travis-ci.org/tiabas/yammer-oauth2
|
10
|
+
[gemnasium]: https://gemnasium.com/tiabas/yammer-oauth2
|
11
|
+
[coveralls]: https://coveralls.io/r/tiabas/yammer-oauth2
|
12
|
+
|
13
|
+
An Ruby wrapper for Yammer's OAuth2 implementation
|
14
|
+
|
15
|
+
For more about the OAuth2 standard checkout: http://tools.ietf.org/html/rfc6749
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
```sh
|
19
|
+
gem install yammer-oauth2
|
20
|
+
```
|
21
|
+
|
22
|
+
## Resources
|
23
|
+
* [View Source on GitHub][code]
|
24
|
+
* [Report Issues on GitHub][issues]
|
25
|
+
* [Website][website]
|
26
|
+
|
27
|
+
[website]: http://tiabas.github.com/yammer-oauth2
|
28
|
+
[code]: https://github.com/tiabas/yammer-oauth2
|
29
|
+
[issues]: https://github.com/tiabas/yammer-oauth2/issues
|
30
|
+
|
31
|
+
## Usage Examples
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
|
35
|
+
require 'yammer-oauth2/client'
|
36
|
+
|
37
|
+
yammer_client = YammmerOAuth2::Client.new('www.yammer.com', 'PRbTcg9qjgKsp4jjpm1pw', 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U')
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## Authorization Grants
|
42
|
+
The client wraps around the creation of any given grant and passing in the parameters defined in the configuration
|
43
|
+
file. The supported grants include Authorization Code and Implicit. They are available via the `authorization_code` and `implicit` methods on a client object.
|
44
|
+
|
45
|
+
### Authorization Code
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
|
49
|
+
# generate authorization url
|
50
|
+
auth_url = yammer_client.webserver_authorization_url
|
51
|
+
# => https://www.yammer.com/dialog/oauth/authorize?client_id=PRbTcg9qjgKsp4jjpm1pw&response_type=code
|
52
|
+
|
53
|
+
# exchange authorization code for access token. we will get back a Net::HTTPResponse
|
54
|
+
response = yammer_client.exchange_auth_code_for_token({
|
55
|
+
:code => '11a0b0b64db56c30e2ef',
|
56
|
+
:redirect_uri => 'https://localhost/callback',
|
57
|
+
})
|
58
|
+
|
59
|
+
response.inspect
|
60
|
+
# => #<Net::HTTPOK:0x007ff8bc7c1200>
|
61
|
+
|
62
|
+
response.body
|
63
|
+
# => {
|
64
|
+
# "access_token" : "e409f4272fe539166a77c42479de030e7660812a",
|
65
|
+
# "token_type" : "bearer"
|
66
|
+
# }"
|
67
|
+
```
|
68
|
+
|
69
|
+
### Implicit Grant
|
70
|
+
```ruby
|
71
|
+
auth_url = client.implicit.authorization_path(:redirect_uri => 'http://localhost/oauth2/callback')
|
72
|
+
# => "https://www.yammer.com/dialog/oauth/?client_id=PRbTcg9qjgKsp4jjpm1pw&redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcallback&response_type=token"
|
73
|
+
```
|
74
|
+
|
75
|
+
# Using a custom Http wrapper
|
76
|
+
By default, yammer-oauth2 uses the `oauth2-client` gem's HTTP wrapper `OAuth2::HttpConnection`. However, if you wish to use a different HTTP library, you only
|
77
|
+
need to create a wrapper around your favorite library that will respond to the `send_request` method.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class TyphoeusHttpConnection
|
81
|
+
|
82
|
+
def initialize(site_url, connection_options={})
|
83
|
+
# set url and connection options
|
84
|
+
@site_url = site_url
|
85
|
+
@connection_options = connection_options
|
86
|
+
end
|
87
|
+
|
88
|
+
def base_url(path)
|
89
|
+
@site_url + path
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_request(http_method, request_path, options={})
|
93
|
+
# options may contain optional arguments like http headers, request parameters etc
|
94
|
+
# send http request over the inter-webs
|
95
|
+
|
96
|
+
params = options[:params] || {}
|
97
|
+
headers = options[:headers]|| {}
|
98
|
+
method = method.to_sym
|
99
|
+
client = Typhoeus
|
100
|
+
|
101
|
+
case method
|
102
|
+
when :get, :delete
|
103
|
+
#pass
|
104
|
+
when :post, :put
|
105
|
+
options[:body] = options.delete(:params) if options[:params]
|
106
|
+
else
|
107
|
+
raise UnhandledHTTPMethodError.new("Unsupported HTTP method, #{method}")
|
108
|
+
end
|
109
|
+
response = client.send(http_method, base_url(request_path), params)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# now you can initialize the OAuth2 client with you custom client and expect that all requests
|
114
|
+
# will be sent using this client
|
115
|
+
oauth_client = YammerOAuth2::Client.new('example.com', client_id, client_secret, {
|
116
|
+
:connection_client => TyphoeusHttpConnection,
|
117
|
+
:connection_options => { :use_ssl => true }
|
118
|
+
})
|
119
|
+
```
|
120
|
+
|
121
|
+
## Supported Ruby Versions
|
122
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
123
|
+
version:
|
124
|
+
|
125
|
+
* Ruby 1.8.7
|
126
|
+
* Ruby 1.9.2
|
127
|
+
* Ruby 1.9.3
|
128
|
+
|
129
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
130
|
+
implementations, however support will only be provided for the versions listed
|
131
|
+
above.
|
132
|
+
|
133
|
+
## Copyright
|
134
|
+
Copyright (c) 2013 Kevin Mutyaba
|
135
|
+
See [LICENSE][license] for details.
|
136
|
+
[license]: https://github.com/tiabas/yammer-oauth2/blob/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAh0aWFi
|
3
|
+
YXNuazEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
4
|
+
MB4XDTEzMDMwMzA2MjAxNVoXDTE0MDMwMzA2MjAxNVowPzERMA8GA1UEAwwIdGlh
|
5
|
+
YmFzbmsxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
6
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMsmVsErcNuwQLKLh9T6
|
7
|
+
a57QiK35g9zjpID2pUBn4alMTmIeAXg2bXWLdAzU0swcjmaGBWz5AaZeqTnnBveO
|
8
|
+
ZDoH6e811uuRjJMYCkLQxhlghEB0TQkAqOnxlj80TN2jFw+YFWLmSnxR4PBonvpp
|
9
|
+
YwWAY0ylqM54FPRhaAIYC5/3Pvx1SYL9/Us0376HEpV0Rty6VXz7tUzv8vFki5ot
|
10
|
+
gyfp5ceWiYIZjQ9Uvhm4luJSfXci13UHZ0AeO7E1padWlx3z8hZIvjawueTGRe5p
|
11
|
+
BgZlI0+xV2ogvAlu8/NCy0hWUwcpnvRdPyBVDRMli8gXGE9jNv8dBWe67vdjzGSk
|
12
|
+
YDUCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFInh
|
13
|
+
qvJkuISNqDOcsrBRotZC0qolMB0GA1UdEQQWMBSBEnRpYWJhc25rQGdtYWlsLmNv
|
14
|
+
bTAdBgNVHRIEFjAUgRJ0aWFiYXNua0BnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
|
15
|
+
ggEBAEGb4gRDulJ9jkf5oRLydfw9UZi6fVWj6aaiJfbbT5NLotpVaWnWdCOO7hy8
|
16
|
+
HDPYWN430zLwr0ODOU9XNueKnEkhnBRiYkcQ0JmYddPkL57kp0qlH4g2IqQfQV2W
|
17
|
+
1b7sE410zFHn55B5nihQY3c0MMSL7wq9Dz2EktbIMikf6sG6zfUgYFE4IQGi2RbO
|
18
|
+
xa5fnTWt7KB5DD02HnHLTZ9Hl2kxlPyWwyjREwNwEjPoSUJFEBiosvAml8frUDA9
|
19
|
+
j6fATg/4fqpgILPVqFIGZOMJDFcJy/oehwwxLu5XMx88WFD9jT1vRj77D7iPLbXd
|
20
|
+
rfGs/qCJKgifXd/1am5hlAH5jXU=
|
21
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module YammerOAuth2
|
4
|
+
class Client < OAuth2::Client
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
super
|
8
|
+
@token_path = '/oauth2/token'
|
9
|
+
@authorize_path = '/dialog/oauth/authorize'
|
10
|
+
end
|
11
|
+
# Generates the Yammer URL that the user will be redirected to in order to
|
12
|
+
# authorize your application
|
13
|
+
#
|
14
|
+
# @see https://developer.yammer.com/api/oauth2.html#client-side
|
15
|
+
#
|
16
|
+
# @opts [Hash] additional parameters to be include in URL eg. scope, state, etc
|
17
|
+
#
|
18
|
+
# client = YammerClient.new(config)
|
19
|
+
# client.clientside_authorization_url({
|
20
|
+
# :redirect_uri => 'https://localhost/oauth/cb',
|
21
|
+
# })
|
22
|
+
# >> https://www.yammer.com/dialog/oauth/?client_id={client_id}&
|
23
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=token
|
24
|
+
#
|
25
|
+
def clientside_authorization_url(opts={})
|
26
|
+
implicit.token_url(opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Generates the Yammer URL that the user will be redirected to in order to
|
30
|
+
# authorize your application
|
31
|
+
#
|
32
|
+
# @see https://developer.yammer.com/api/oauth2.html#server-side
|
33
|
+
#
|
34
|
+
# @opts [Hash] additional parameters to be include in URL eg. scope, state, etc
|
35
|
+
#
|
36
|
+
# >> client = YammerClient.new(config)
|
37
|
+
# >> client.webserver_authorization_url({
|
38
|
+
# :redirect_uri => 'https://localhost/oauth/cb',
|
39
|
+
# })
|
40
|
+
# >> https://www.yammer.com/dialog/oauth/?client_id={client_id}&
|
41
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=code
|
42
|
+
#
|
43
|
+
def webserver_authorization_url(opts={})
|
44
|
+
opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
|
45
|
+
authorization_code.authorization_url(opts)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generates the Yammer URL that the user will be redirected to in order to
|
49
|
+
# authorize your application
|
50
|
+
#
|
51
|
+
# @see https://developer.yammer.com/api/oauth2.html#server-side
|
52
|
+
#
|
53
|
+
# @opts [Hash] additional parameters to be include in URL eg. scope, state, etc
|
54
|
+
#
|
55
|
+
# >> client = YammerClient.new(config)
|
56
|
+
# >> client.webserver_authorization_url({
|
57
|
+
# :client_secret => @client_secret
|
58
|
+
# :code => 'G3Y6jU3a',
|
59
|
+
# :redirect_uri => 'https://localhost/oauth/cb',
|
60
|
+
# })
|
61
|
+
# >> https://www.yammer.com/oauth2/access_token?client_id={client_id}&
|
62
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&client_secret={client_secret}&
|
63
|
+
# grant_type=authorization_code&code=aXW2c6bYz
|
64
|
+
#
|
65
|
+
def webserver_token_url(opts={})
|
66
|
+
opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
|
67
|
+
opts[:client_secret] = @client_secret
|
68
|
+
authorization_code.token_path(opts)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Makes a request to Yammer server that will swap your authorization code for an access
|
72
|
+
# token
|
73
|
+
#
|
74
|
+
# @see https://developer.yammer.com/api/oauth2.html#server-side
|
75
|
+
#
|
76
|
+
# @opts [Hash] must include authorization code and redirect uri in additon to others
|
77
|
+
#
|
78
|
+
# >> client = YammerClient.new(config)
|
79
|
+
# >> client.exchange_auth_code_for_token({
|
80
|
+
# :redirect_uri => 'https://localhost:3000/oauth/v2/callback',
|
81
|
+
# :code => 'G3Y6jU3a',
|
82
|
+
# })
|
83
|
+
#
|
84
|
+
# POST /oauth2/access_token HTTP/1.1
|
85
|
+
# Host: www.yammer.com
|
86
|
+
# Content-Type: application/x-www-form-urlencoded
|
87
|
+
|
88
|
+
# client_id={client_id}&code=G3Y6jU3a&grant_type=authorization_code&
|
89
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&client_secret={client_secret}
|
90
|
+
|
91
|
+
def exchange_auth_code_for_token(opts={})
|
92
|
+
unless (opts[:params] && opts[:params][:code])
|
93
|
+
raise ArgumentError.new("You must include an authorization code as a parameter")
|
94
|
+
end
|
95
|
+
opts[:authenticate] ||= :body
|
96
|
+
code = opts[:params].delete(:code)
|
97
|
+
authorization_code.get_token(code, opts)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe YammerOAuth2::Client do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
YammerOAuth2::Client.new('https://www.yammer.com', 'PRbTcg9qjgKsp4jjpm1pw', 'a2nQpcUm2Dgq1chWdAvbXGTk', {
|
7
|
+
:connection_options => {
|
8
|
+
:headers => {
|
9
|
+
'User-Agent' => "Yammer OAuth2 Gem #{YammerOAuth2::Version}",
|
10
|
+
"Accept" => "application/json"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#clientside_authorization_url" do
|
17
|
+
it "returns url string for obtaining authorization" do
|
18
|
+
params = {
|
19
|
+
'client_id' => 'PRbTcg9qjgKsp4jjpm1pw',
|
20
|
+
'response_type' => 'token'
|
21
|
+
}
|
22
|
+
|
23
|
+
auth_url = subject.clientside_authorization_url
|
24
|
+
|
25
|
+
parsed_url = Addressable::URI.parse(auth_url)
|
26
|
+
expect(parsed_url.path).to eq '/dialog/oauth/authorize'
|
27
|
+
expect(parsed_url.query_values).to eq params
|
28
|
+
expect(parsed_url.scheme).to eq 'https'
|
29
|
+
expect(parsed_url.host).to eq 'www.yammer.com'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#webserver_authorization_url" do
|
34
|
+
it "returns the authorization url" do
|
35
|
+
params = {
|
36
|
+
"client_id" => "PRbTcg9qjgKsp4jjpm1pw",
|
37
|
+
"redirect_uri" => "https://localhost/callback",
|
38
|
+
"response_type" =>"code",
|
39
|
+
"state" => "12345"
|
40
|
+
}
|
41
|
+
|
42
|
+
auth_url = subject.webserver_authorization_url(
|
43
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
44
|
+
:state => '12345',
|
45
|
+
:redirect_uri => 'https://localhost/callback'
|
46
|
+
)
|
47
|
+
|
48
|
+
parsed_url = Addressable::URI.parse(auth_url)
|
49
|
+
expect(parsed_url.path).to eq '/dialog/oauth/authorize'
|
50
|
+
expect(parsed_url.query_values).to eq params
|
51
|
+
expect(parsed_url.scheme).to eq 'https'
|
52
|
+
expect(parsed_url.host).to eq 'www.yammer.com'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#exchange_auth_code_for_token" do
|
57
|
+
it "makes a request to google oauth2 server" do
|
58
|
+
|
59
|
+
stub_request(:post, "https://www.yammer.com/oauth2/token").with(
|
60
|
+
:body => {
|
61
|
+
:grant_type => 'authorization_code',
|
62
|
+
:code => 'MmOGL795LbIZuJJVnL49Cc',
|
63
|
+
:redirect_uri => 'https://localhost',
|
64
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
65
|
+
:client_secret => 'a2nQpcUm2Dgq1chWdAvbXGTk'
|
66
|
+
},
|
67
|
+
:headers => {
|
68
|
+
'Accept' => "application/json",
|
69
|
+
'User-Agent' => "Yammer OAuth2 Gem #{YammerOAuth2::Version}",
|
70
|
+
'Content-Type' => "application/x-www-form-urlencoded"
|
71
|
+
}
|
72
|
+
)
|
73
|
+
response = subject.exchange_auth_code_for_token(
|
74
|
+
:params => {
|
75
|
+
:code => 'MmOGL795LbIZuJJVnL49Cc',
|
76
|
+
:redirect_uri => 'https://localhost'
|
77
|
+
}
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'yammer-oauth2'
|
11
|
+
require 'rspec'
|
12
|
+
require 'rspec/autorun'
|
13
|
+
require 'webmock/rspec'
|
14
|
+
|
15
|
+
WebMock.disable_net_connect!(:allow => 'coveralls.io')
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.mock_with :rspec
|
19
|
+
config.expect_with :rspec do |c|
|
20
|
+
c.syntax = :expect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_delete(path)
|
25
|
+
stub_request(:delete, 'https://example.com' + path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_get(path)
|
29
|
+
stub_request(:get, 'https://example.com' + path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_post(path)
|
33
|
+
stub_request(:post, 'https://example.com' + path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_put(path)
|
37
|
+
stub_request(:put, 'https://example.com' + path)
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'yammer-oauth2'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.add_dependency 'oauth2-client', '~> 1.1.2'
|
7
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
8
|
+
|
9
|
+
spec.authors = ["Kevin Mutyaba"]
|
10
|
+
spec.date = %q{2013-03-03}
|
11
|
+
spec.description = "A Yammer OAuth2 wrapper"
|
12
|
+
spec.email = %q{tiabasnk@gmail.com}
|
13
|
+
spec.files = `git ls-files`.split("\n")
|
14
|
+
spec.homepage = 'http://tiabas.github.com/yammer-oauth2/'
|
15
|
+
spec.licenses = ['MIT']
|
16
|
+
spec.name = 'yammer-oauth2'
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
spec.required_rubygems_version = '>= 1.3.6'
|
19
|
+
spec.summary = "OAuth2 client wrapper for Yammer"
|
20
|
+
spec.version = YammerOAuth2::Version
|
21
|
+
|
22
|
+
spec.cert_chain = ['certs/tiabas-public.pem']
|
23
|
+
spec.signing_key = File.expand_path("~/.gem/certs/private_key.pem")
|
24
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yammer-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Mutyaba
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURjRENDQWxpZ0F3SUJB
|
14
|
+
Z0lCQVRBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJFd0R3WURWUVFEREFoMGFX
|
15
|
+
RmkKWVhOdWF6RVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VR
|
16
|
+
WUtDWkltaVpQeUxHUUJHUllEWTI5dApNQjRYRFRFek1ETXdNekEyTWpBeE5W
|
17
|
+
b1hEVEUwTURNd016QTJNakF4TlZvd1B6RVJNQThHQTFVRUF3d0lkR2xoCllt
|
18
|
+
RnpibXN4RlRBVEJnb0praWFKay9Jc1pBRVpGZ1ZuYldGcGJERVRNQkVHQ2dt
|
19
|
+
U0pvbVQ4aXhrQVJrV0EyTnYKYlRDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFB
|
20
|
+
RGdnRVBBRENDQVFvQ2dnRUJBTXNtVnNFcmNOdXdRTEtMaDlUNgphNTdRaUsz
|
21
|
+
NWc5empwSUQycFVCbjRhbE1UbUllQVhnMmJYV0xkQXpVMHN3Y2ptYUdCV3o1
|
22
|
+
QWFaZXFUbm5CdmVPClpEb0g2ZTgxMXV1UmpKTVlDa0xReGhsZ2hFQjBUUWtB
|
23
|
+
cU9ueGxqODBUTjJqRncrWUZXTG1TbnhSNFBCb252cHAKWXdXQVkweWxxTTU0
|
24
|
+
RlBSaGFBSVlDNS8zUHZ4MVNZTDkvVXMwMzc2SEVwVjBSdHk2Vlh6N3RVenY4
|
25
|
+
dkZraTVvdApneWZwNWNlV2lZSVpqUTlVdmhtNGx1SlNmWGNpMTNVSFowQWVP
|
26
|
+
N0UxcGFkV2x4M3o4aFpJdmphd3VlVEdSZTVwCkJnWmxJMCt4VjJvZ3ZBbHU4
|
27
|
+
L05DeTBoV1V3Y3BudlJkUHlCVkRSTWxpOGdYR0U5ak52OGRCV2U2N3ZkanpH
|
28
|
+
U2sKWURVQ0F3RUFBYU4zTUhVd0NRWURWUjBUQkFJd0FEQUxCZ05WSFE4RUJB
|
29
|
+
TUNCTEF3SFFZRFZSME9CQllFRkluaApxdkprdUlTTnFET2NzckJSb3RaQzBx
|
30
|
+
b2xNQjBHQTFVZEVRUVdNQlNCRW5ScFlXSmhjMjVyUUdkdFlXbHNMbU52CmJU
|
31
|
+
QWRCZ05WSFJJRUZqQVVnUkowYVdGaVlYTnVhMEJuYldGcGJDNWpiMjB3RFFZ
|
32
|
+
SktvWklodmNOQVFFRkJRQUQKZ2dFQkFFR2I0Z1JEdWxKOWprZjVvUkx5ZGZ3
|
33
|
+
OVVaaTZmVldqNmFhaUpmYmJUNU5Mb3RwVmFXbldkQ09PN2h5OApIRFBZV040
|
34
|
+
MzB6THdyME9ET1U5WE51ZUtuRWtobkJSaVlrY1EwSm1ZZGRQa0w1N2twMHFs
|
35
|
+
SDRnMklxUWZRVjJXCjFiN3NFNDEwekZIbjU1QjVuaWhRWTNjME1NU0w3d3E5
|
36
|
+
RHoyRWt0YklNaWtmNnNHNnpmVWdZRkU0SVFHaTJSYk8KeGE1Zm5UV3Q3S0I1
|
37
|
+
REQwMkhuSExUWjlIbDJreGxQeVd3eWpSRXdOd0VqUG9TVUpGRUJpb3N2QW1s
|
38
|
+
OGZyVURBOQpqNmZBVGcvNGZxcGdJTFBWcUZJR1pPTUpERmNKeS9vZWh3d3hM
|
39
|
+
dTVYTXg4OFdGRDlqVDF2Umo3N0Q3aVBMYlhkCnJmR3MvcUNKS2dpZlhkLzFh
|
40
|
+
bTVobEFINWpYVT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|
41
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
42
|
+
dependencies:
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: oauth2-client
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ~>
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.1.2
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.1.2
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
description: A Yammer OAuth2 wrapper
|
76
|
+
email: tiabasnk@gmail.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- .travis.yml
|
83
|
+
- CHANGELOG.md
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- LICENSE.md
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- certs/tiabas-public.pem
|
90
|
+
- lib/yammer-oauth2/client.rb
|
91
|
+
- lib/yammer-oauth2/version.rb
|
92
|
+
- spec/client_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- yammer-oauth2.gemspec
|
95
|
+
homepage: http://tiabas.github.com/yammer-oauth2/
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.3.6
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.25
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: OAuth2 client wrapper for Yammer
|
120
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�l����X�Ӎ
|