omniauth-participa 1.0.0.rc2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d8e114a9af2bbcfe67794342f9e70c74fd5b01e
4
- data.tar.gz: cebfdec065ada3ca1ccc9f984b9c0a37382fdeea
3
+ metadata.gz: 4480684a332639fdcd83f2947774928c61063f32
4
+ data.tar.gz: 98395a3520604b7d3b969f94e265ad1135407074
5
5
  SHA512:
6
- metadata.gz: 318ea0037a4f0e6f40ed1ed91aa7cbd9d7a64dbf44595f669d0714c5370699198d638172a060cfa8259275de99c3b6eb6ed853f1201b6ebe1c35e3d3870771ed
7
- data.tar.gz: 6abc85c22e3e10ad2af33aad8b9bff305673c7ea2b4f027529ac045c386150ee9f3d75c8e1f6eb2b6a52aaf37f61b9f3395c612c16d0adbb98388ccb25cad1f9
6
+ metadata.gz: f82ae4dc2281844106d2f5039d114addca98c9aa7a095771ec5657295f7d838de5b926d2607496255670964e17424082c22b2217607d6977c74cf423443b9756
7
+ data.tar.gz: 45b03a7f6d0458423805a459ab6b7495d65b0409b56162d696d103f67fd8669d24669f079134c7d8344b7611e119cd0fbd9dc9324ab7dc9ee5d789a79c4ca65a
data/README.md CHANGED
@@ -1,8 +1,20 @@
1
- # Omniauth::Participa
1
+ # Omniauth Participa
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/participa`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/omniauth-participa.svg)](https://badge.fury.io/rb/omniauth-participa)
4
+ [![Build Status](https://travis-ci.org/adab1ts/omniauth-participa.svg?branch=master)](https://travis-ci.org/adab1ts/omniauth-participa)
5
+ [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://choosealicense.com/licenses/mit/)
6
+
7
+ This gem contains the [OmniAuth](https://github.com/omniauth/omniauth) strategy for [Participa](https://github.com/GuanyemBarcelona/participa) platform.
8
+
9
+
10
+ ## Before You Begin
11
+
12
+ [Participa](https://github.com/GuanyemBarcelona/participa) supports [OAuth 2](https://www.oauth.com/) authentication, playing the [Authorization and Resource Server](https://aaronparecki.com/oauth-2-simplified/#roles) roles.
13
+
14
+ Participa uses the _Authorization Code_ grant to authorize Client apps acting on behalf the user. Contact the platform admin and ask for a **Client ID** and a **Client Secret** for your application. Remember to provide your **Redirect URI**:
15
+
16
+ `https://your-application.domain/auth/participa/callback`.
4
17
 
5
- TODO: Delete this and the text above, and describe your gem
6
18
 
7
19
  ## Installation
8
20
 
@@ -20,9 +32,85 @@ Or install it yourself as:
20
32
 
21
33
  $ gem install omniauth-participa
22
34
 
35
+
23
36
  ## Usage
24
37
 
25
- TODO: Write usage instructions here
38
+ `OmniAuth::Strategies::Participa` is simply a Rack middleware. Tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
39
+
40
+ ```ruby
41
+ # config/initializers/omniauth.rb
42
+
43
+ Rails.application.config.middleware.use OmniAuth::Builder do
44
+ provider :participa, ENV['PARTICIPA_CLIENT_ID'], ENV['PARTICIPA_CLIENT_SECRET']
45
+ end
46
+ ```
47
+
48
+
49
+ ## Configuration
50
+
51
+ You can configure several options, which you pass in to the `provider` method via a `Hash`:
52
+
53
+ Option name | Default | Explanation
54
+ --- | --- | ---
55
+ `site` | `https://participa.dev` | URL of the Participa server instance (e.g. https://the-server-app.com)
56
+ `authorize_url` | `/oauth/authorize` | Authorization URL for Participa (e.g. https://the-server-app.com/oauth/authorize)
57
+ `token_url` | `/oauth/token` | Token URL for Participa (e.g. https://the-server-app.com/oauth/token)
58
+ `endpoint_url` | `/api/v2/users/me` | User endpoint URL for Participa (e.g. https://the-server-app.com/api/v2/users/me)'
59
+ `redirect_uri` | | Custom callback URL used during the server-side flow (e.g. https://the-client-app.com/auth/participa/callback)
60
+
61
+ Here's an example of a possible configuration:
62
+
63
+ ```ruby
64
+ # config/initializers/omniauth.rb
65
+
66
+ Rails.application.config.middleware.use OmniAuth::Builder do
67
+ provider :participa, ENV['PARTICIPA_CLIENT_ID'], ENV['PARTICIPA_CLIENT_SECRET'],
68
+ {
69
+ redirect_uri: 'https://the-client-app.com/auth/participa/callback',
70
+ client_options: {
71
+ site: 'https://the-server-app.com',
72
+ authorize_url: 'https://the-server-app.com/oauth/authorize',
73
+ token_url: 'https://the-server-app.com/oauth/token',
74
+ endpoint_url: 'https://the-server-app.com/api/v2/users/me'
75
+ }
76
+ }
77
+ end
78
+ ```
79
+
80
+
81
+ ## Auth Hash
82
+
83
+ Here's an example _Auth Hash_ available in the callback by accessing `request.env['omniauth.auth']`:
84
+
85
+ ```ruby
86
+ {
87
+ provider: 'participa',
88
+ uid: '12345',
89
+ info: {
90
+ email: 'jane.doe@acme.com',
91
+ name: 'Jane Doe',
92
+ username: 'Jane_Doe',
93
+ admin: true
94
+ },
95
+ credentials: {
96
+ token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
97
+ refresh_token: "FEDCBA...",
98
+ expires_at: 1321747205, # when the access token expires (it always will),
99
+ expires: true # this will always be true
100
+ }
101
+ extra: {
102
+ raw_info: {
103
+ id: '12345',
104
+ email: 'jane.doe@acme.com',
105
+ full_name: 'Jane Doe',
106
+ username: 'Jane_Doe',
107
+ admin: true,
108
+ list_groups: ['group-1', 'group-2']
109
+ }
110
+ }
111
+ }
112
+ ```
113
+
26
114
 
27
115
  ## Development
28
116
 
@@ -30,11 +118,26 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
118
 
31
119
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
120
 
33
- ## Contributing
34
121
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/adab1ts/omniauth-participa.
122
+ ## Contact
123
+
124
+ Email: info[@]adabits[.]org
125
+ Twitter: [@adab1ts](https://twitter.com/adab1ts)
126
+ Facebook: [Adab1ts](https://www.facebook.com/Adab1ts)
127
+ LinkedIn: [adab1ts](https://www.linkedin.com/company/adab1ts)
128
+
129
+
130
+ ## Contributors
131
+
132
+ Contributions of any kind are welcome!
133
+
134
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
135
+ <img alt="laklau" src="https://avatars.githubusercontent.com/u/6210292?v=3&s=117" width="117"> |[<img alt="zuzust" src="https://avatars.githubusercontent.com/u/351530?v=3&s=117" width="117">](https://github.com/adab1ts/omniauth-participa/commits?author=zuzust) |
136
+ :---: |:---: |
137
+ [Klaudia Alvarez](https://github.com/laklau) |[Carles Muiños](https://github.com/zuzust)
138
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
36
139
 
37
140
 
38
141
  ## License
39
142
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
143
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Participa
3
- VERSION = '1.0.0.rc2'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -7,10 +7,9 @@ module OmniAuth
7
7
  option :name, :participa
8
8
  option :scope, 'public'
9
9
  option :authorize_options, [:redirect_uri, :scope]
10
- option :provider_ignores_state, true
11
10
 
12
11
  option :client_options, {
13
- site: 'http://participa.dev',
12
+ site: 'https://participa.dev',
14
13
  authorize_url: '/oauth/authorize',
15
14
  token_url: '/oauth/token',
16
15
  endpoint_url: '/api/v2/users/me'
@@ -37,13 +36,12 @@ module OmniAuth
37
36
  }
38
37
  end
39
38
 
40
- # TODO: add user groups
41
39
  extra do
42
40
  skip_info? ? {} : { raw_info: raw_info }
43
41
  end
44
42
 
45
43
  def raw_info
46
- @raw_info ||= access_token.get(options[:client_options].try(:endpoint_url)).parsed
44
+ @raw_info ||= access_token.get(options[:client_options][:endpoint_url]).parsed
47
45
  end
48
46
 
49
47
  # https://github.com/intridea/omniauth-oauth2/issues/81
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe OmniAuth::Strategies::Participa do
4
4
  let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
5
5
  let(:app) { -> {[200, {}, ['Participa']]} }
6
- let(:raw_info) { {'id' => 'uid', 'admin' => true, 'email' => 'jane-doe@example.com', 'username' => 'jane-doe', 'full_name' => 'Jane Doe'} }
6
+ let(:raw_info) {
7
+ {'id' => 'uid', 'admin' => true, 'email' => 'jane-doe@example.com', 'username' => 'jane-doe', 'full_name' => 'Jane Doe'}
8
+ }
7
9
 
8
10
  subject do
9
11
  OmniAuth::Strategies::Participa.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
@@ -72,8 +74,8 @@ describe OmniAuth::Strategies::Participa do
72
74
  end
73
75
 
74
76
  it 'should set the redirect_uri parameter if present' do
75
- @options = { redirect_uri: 'htts://example.com/auth/participa/callback' }
76
- expect(subject.authorize_params['redirect_uri']).to eq('htts://example.com/auth/participa/callback')
77
+ @options = { redirect_uri: 'https://example.com/auth/participa/callback' }
78
+ expect(subject.authorize_params['redirect_uri']).to eq('https://example.com/auth/participa/callback')
77
79
  end
78
80
  end
79
81
 
@@ -105,6 +107,27 @@ describe OmniAuth::Strategies::Participa do
105
107
  end
106
108
  end
107
109
 
110
+ describe '#callback_url' do
111
+ it 'should return the redirect_uri parameter if present' do
112
+ @options = { redirect_uri: 'https://example.com/auth/foo/callback' }
113
+ expect(subject.callback_url).to eq('https://example.com/auth/foo/callback')
114
+ end
115
+ end
116
+
117
+ describe '#raw_info' do
118
+ before do
119
+ access_token = double('access_token')
120
+ response = double('response', parsed: { foo: 'bar' })
121
+
122
+ expect(access_token).to receive(:get).with('/api/v2/users/me').and_return(response)
123
+ allow(subject).to receive(:access_token) { access_token }
124
+ end
125
+
126
+ it 'returns parsed response from access token' do
127
+ expect(subject.raw_info).to eq({ foo: 'bar'})
128
+ end
129
+ end
130
+
108
131
  describe '#uid' do
109
132
  it 'should return the user id' do
110
133
  allow(subject).to receive(:raw_info).and_return(raw_info)
@@ -133,4 +156,26 @@ describe OmniAuth::Strategies::Participa do
133
156
  expect(subject.info[:admin]).to eq(raw_info['admin'])
134
157
  end
135
158
  end
159
+
160
+ describe '#extra' do
161
+ before do
162
+ allow(subject).to receive(:raw_info).and_return(raw_info)
163
+ end
164
+
165
+ context "when skip info is true" do
166
+ before { subject.options.skip_info = true }
167
+
168
+ it 'should not include raw_info' do
169
+ expect(subject.extra).not_to have_key(:raw_info)
170
+ end
171
+ end
172
+
173
+ context "when skip info is false" do
174
+ before { subject.options.skip_info = false }
175
+
176
+ it 'should include raw_info' do
177
+ expect(subject.extra[:raw_info]).to eq(raw_info)
178
+ end
179
+ end
180
+ end
136
181
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-participa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carles Muiños
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -119,9 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '2.3'
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 1.3.1
124
+ version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
127
  rubygems_version: 2.5.1