omniauth-wild-apricot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f0c62dcf02e3d0513ff7299b3b9abc039bfd33e774561678cebb57d61eeca913
4
+ data.tar.gz: a7aaa8b0cfbbd7962c663866f373e0731b8dfac31ca113844b4c5d7d6a35eba5
5
+ SHA512:
6
+ metadata.gz: 3916f9ac8974301f7a89ee3526c8a5d30abb7a3fd644985334b7d184c9e125ac770967a06037e1636b3f124b6eab726402de5271b54f79e9d9e3d54c500b6102
7
+ data.tar.gz: 1bfa9dbb3ff22ddda09582f2b2ede7d1b7aa4d872a6e416bf3c251385d56ea0609adc1b3180c630921960769ad8508133f522fb639b86819f4336d600266ad8d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-gemset
7
+ .ruby-version
8
+ .rvmrc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ .powenv
22
+ .idea/
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## 0.1.0 - 2023-08-31
5
+
6
+ ### Added
7
+ - First version
8
+
9
+ ### Deprecated
10
+ - Nothing
11
+
12
+ ### Removed
13
+ - Nothing
14
+
15
+ ### Fixed
16
+ - Nothing
17
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # OmniAuth WildApricot OAuth2 Strategy
2
+
3
+ Strategy to authenticate with WildApricot via OAuth2 in OmniAuth.
4
+
5
+ For more details, read the WildApricot docs: https://gethelp.wildapricot.com/en/articles/200-single-sign-on-service-sso
6
+
7
+ ## Installation
8
+
9
+ First start by adding this gem to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-wild-apricot'
13
+ ```
14
+
15
+ If you need to use the latest HEAD version, you can do so with:
16
+
17
+ ```ruby
18
+ gem 'omniauth-wild-apricot', github: 'rocket-house/omniauth-wild-apricot'
19
+ ```
20
+
21
+ Then `bundle install`.
22
+
23
+ ## WildApricot API Setup
24
+
25
+ Go to 'https://myWAsite.com/admin/apps/integration/authorized-applications/' then:
26
+
27
+ * Select 'Authorize Application', then select 'Server Application'
28
+ * Name your application
29
+ * Select desired permission level: read/write
30
+ * Click 'Generate client secret'
31
+ * Select 'Authorize users via Wild Apricot single sign-on service'
32
+ * Fill in your app's redirect domain
33
+ * Take note of the following information:
34
+ * Client ID
35
+ * Client Secret
36
+
37
+ Additionally, you'll need your Wild Apricot Account # which can be found on the admin/billing page. You also need your site's url. If you're billing page is 'https://myWAsite.com/admin/billing/' then your site url is 'https://myWAsite.com/'.
38
+
39
+ The above information can be placed into your project's `.env` file (see `examples/.env-example`), or set as environment variables in your hosting provider's application settings.
40
+
41
+ ## Usage using OmniAuth
42
+
43
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`. In this example, we are storing the key variables in the project's `.env` file (see `examples/.env-example`).
44
+
45
+ ```ruby
46
+ Rails.application.config.middleware.use OmniAuth::Builder do
47
+ provider :wild_apricot, ENV['WA_CLIENT_ID'], ENV['WA_CLIENT_SECRET'],
48
+ {
49
+ account_num: ENV['WA_ACCT_NUM'], # found at: https://myWAsite.com/admin/billing/
50
+ site_url: ENV['WA_SITE_URL'], # set to: 'https://myWAsite.com/'
51
+ callback_path: '/path/to/callback'
52
+ }
53
+ end
54
+ ```
55
+
56
+ ## Usage using Devise
57
+
58
+ If you are using [Devise](https://github.com/plataformatec/devise) then it will look like this:
59
+
60
+ ```ruby
61
+ Devise.setup do |config|
62
+ # other stuff...
63
+
64
+ config.omniauth :wild_apricot, ENV['WA_CLIENT_ID'], ENV['WA_CLIENT_SECRET'],
65
+ {
66
+ account_num: ENV['WA_ACCT_NUM'], # found at: https://myWAsite.com/admin/billing/
67
+ site_url: ENV['WA_SITE_URL'] # set to: 'https://myWAsite.com/'
68
+ }
69
+
70
+ # other stuff...
71
+ end
72
+ ```
73
+
74
+ **NOTE:** If you are using this gem with devise with above snippet in `config/initializers/devise.rb` then do not create `config/initializers/omniauth.rb` which will conflict with devise configurations.
75
+
76
+ Then add the following to 'config/routes.rb' so the callback routes are defined.
77
+
78
+ ```ruby
79
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
80
+ ```
81
+
82
+ Make sure your model is omniauthable. Generally this is "/app/models/user.rb"
83
+
84
+ ```ruby
85
+ devise :omniauthable, omniauth_providers: [:wild_apricot]
86
+ ```
87
+
88
+ Then make sure your callbacks controller is setup.
89
+
90
+ ```ruby
91
+ # app/controllers/users/omniauth_callbacks_controller.rb:
92
+
93
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
94
+ def wild_apricot
95
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
96
+ @user = User.from_omniauth(request.env['omniauth.auth'])
97
+
98
+ if @user.persisted?
99
+ flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Wild Apricot'
100
+ sign_in_and_redirect @user, event: :authentication
101
+ else
102
+ session['devise.wild_apricot_data'] = request.env['omniauth.auth'].except('extra') # Removing extra as it can overflow some session stores
103
+ redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
104
+ end
105
+ end
106
+ end
107
+ ```
108
+
109
+ and bind to or create the user
110
+
111
+ ```ruby
112
+ def self.from_omniauth(access_token)
113
+ data = access_token.info
114
+ user = User.where(email: data['email']).first
115
+
116
+ # Uncomment the section below if you want users to be created if they don't exist
117
+ # unless user
118
+ # user = User.create(name: data['name'],
119
+ # email: data['email'],
120
+ # password: Devise.friendly_token[0,20]
121
+ # )
122
+ # end
123
+ user
124
+ end
125
+ ```
126
+
127
+ For your views you can login using:
128
+
129
+ ```erb
130
+ <%# omniauth-wild-apricot 1.0.x uses OmniAuth 2 and requires using HTTP Post to initiate authentication: %>
131
+ <%= link_to "Sign in with Wild Apricot", user_wild_apricot_omniauth_authorize_path, method: :post %>
132
+
133
+ <%# omniauth-wild-apricot prior 1.0.0: %>
134
+ <%= link_to "Sign in with Wild Apricot", user_wild_apricot_omniauth_authorize_path %>
135
+
136
+ <%# Devise prior 4.1.0: %>
137
+ <%= link_to "Sign in with Wild Apricot", user_omniauth_authorize_path(:wild_apricot) %>
138
+ ```
139
+
140
+ An overview is available at https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
141
+
142
+ ## Auth Hash
143
+
144
+ Here's an example of an authentication hash available in the callback by accessing `request.env['omniauth.auth']`:
145
+
146
+ ```ruby
147
+ {
148
+ "provider":"wild_apricot",
149
+ "uid":"50152421",
150
+ "info":{
151
+ "email":"anita.borg@example.com",
152
+ "first_name":"Anita",
153
+ "last_name":"Borg",
154
+ "name":"Anita Borg"
155
+ },
156
+ "credentials":{
157
+ "token":"thaXd6xjo4qpQnwraebbGA40vzg-",
158
+ "refresh_token":"rt_2023-09-02_VguuDxHFznplhQk1YaOtNrxcgyk-",
159
+ "expires_at":1693689961,
160
+ "expires":true
161
+ },
162
+ "extra":{
163
+ "raw_info":{
164
+ "AdministrativeRoleTypes":["AccountAdministrator"],
165
+ "FirstName":"Anita",
166
+ "LastName":"Anita",
167
+ "Email":"anita.borg@example.com",
168
+ "DisplayName":"Anita, Anita",
169
+ "PasswordExpiration":"2024-08-17T05:42:03+00:00",
170
+ "MembershipLevel":{
171
+ "Id":1253690,
172
+ "Url":"https://api.wildapricot.org/v2/accounts/321456/MembershipLevels/1253690",
173
+ "Name":"FREE"
174
+ },
175
+ "Status":"Active",
176
+ "Id":50152421,
177
+ "Url":"https://api.wildapricot.org/v2/accounts/321456/Contacts/50152421",
178
+ "IsAccountAdministrator":true,
179
+ "TermsOfUseAccepted":true
180
+ }
181
+ }
182
+ }
183
+ ```
184
+
185
+ ## Fixing Protocol Mismatch for `redirect_uri` in Rails
186
+
187
+ Just set the `full_host` in OmniAuth based on the Rails.env.
188
+
189
+ ```
190
+ # config/initializers/omniauth.rb
191
+ OmniAuth.config.full_host = Rails.env.production? ? 'https://domain.com' : 'http://localhost:3000'
192
+ ```
193
+
194
+ ## Contributing
195
+
196
+ 1. Fork it
197
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
198
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
199
+ 4. Push to the branch (`git push origin my-new-feature`)
200
+ 5. Create new Pull Request
201
+
202
+ ## License
203
+
204
+ Copyright (c) 2023 by Fred Zirdung
205
+
206
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
207
+
208
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
209
+
210
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join('bundler', 'gem_tasks')
4
+ require File.join('rspec', 'core', 'rake_task')
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ WA_ACCT_NUM='FIXME'
2
+ WA_SITE_URL='FIXME'
3
+ WA_CLIENT_ID='FIXME'
4
+ WA_CLIENT_SECRET='FIXME'
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oauth2'
4
+ require 'omniauth-oauth2'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class WildApricot < OmniAuth::Strategies::OAuth2
9
+
10
+ DEFAULT_SCOPE = 'contacts_me'
11
+ AUTHORIZE_URL = '/sys/login/OAuthLogin'
12
+ BASE_API_URL = 'https://api.wildapricot.org/v2'
13
+ TOKEN_URL = 'https://oauth.wildapricot.org/auth/token'
14
+
15
+ option :name, 'wild_apricot'
16
+
17
+ # override the base class param functions -- this
18
+ # allows us to use values in the `options` hash at
19
+ # run time insead of setting the values at load time
20
+ #
21
+ # the options hash contains user-defined values not
22
+ # available at class load time
23
+
24
+ def authorize_params
25
+ super.merge({
26
+ scope: DEFAULT_SCOPE,
27
+ response_type: 'authorization_code',
28
+ claimed_account_id: options.account_num
29
+ })
30
+ end
31
+
32
+ def token_params
33
+ super.merge({
34
+ headers: {
35
+ 'Authorization' => "Basic #{authorization_header}"
36
+ },
37
+ })
38
+ end
39
+
40
+ # pull values from the options hash at run time instead
41
+ # of static values at class load time (using `option`)
42
+
43
+ def client_options
44
+ {
45
+ site: options.site,
46
+ authorize_url: AUTHORIZE_URL,
47
+ token_url: TOKEN_URL
48
+ }
49
+ end
50
+
51
+ # override the default client so we can use the `client_options`
52
+ # funciton instead of the values set via the `option` function
53
+
54
+ def client
55
+ ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options))
56
+ end
57
+
58
+ # standard strategy implementation stuff below here
59
+
60
+ uid { raw_info['Id'].to_s }
61
+
62
+ info do
63
+ {
64
+ email: raw_info['Email'],
65
+ first_name: raw_info['FirstName'],
66
+ last_name: raw_info['LastName'],
67
+ name: "#{raw_info['FirstName']} #{raw_info['LastName']}"
68
+ }
69
+ end
70
+
71
+ extra do
72
+ {
73
+ raw_info: raw_info
74
+ }
75
+ end
76
+
77
+ def raw_info
78
+ @raw_info ||= access_token.get(contact_url).parsed
79
+ end
80
+
81
+ def callback_url
82
+ full_host + script_name + callback_path
83
+ end
84
+
85
+ private #######################################################
86
+
87
+ def contact_url
88
+ "#{BASE_API_URL}/Accounts/#{options.account_num}/Contacts/Me"
89
+ end
90
+
91
+ def authorization_header
92
+ Base64.strict_encode64("#{options.client_id}:#{options.client_secret}")
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module WildApricot
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/wild_apricot'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/wild_apricot'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'wild_apricot', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-wild-apricot'
10
+ gem.version = OmniAuth::WildApricot::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A WildApricot OAuth2 strategy for OmniAuth 1.x)
13
+ gem.description = %(A WildApricot OAuth2 strategy for OmniAuth 1.x. This allows you to login to WildApricot with your ruby app.)
14
+ gem.authors = ['Fred Zirdung']
15
+ gem.email = ['fred@rocket-house.com']
16
+ gem.homepage = 'https://github.com/rocket-house/omniauth-wild-apricot'
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.required_ruby_version = '>= 2.2'
22
+
23
+ gem.add_runtime_dependency 'oauth2', '~> 2.0'
24
+ gem.add_runtime_dependency 'omniauth', '~> 2.0'
25
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.8'
26
+
27
+ gem.add_development_dependency 'rake', '~> 12.0'
28
+ gem.add_development_dependency 'rspec', '~> 3.6'
29
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join('bundler', 'setup')
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-wild-apricot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fred Zirdung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ description: A WildApricot OAuth2 strategy for OmniAuth 1.x. This allows you to login
84
+ to WildApricot with your ruby app.
85
+ email:
86
+ - fred@rocket-house.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - examples/.env-example
97
+ - lib/omniauth-wild-apricot.rb
98
+ - lib/omniauth/strategies/wild_apricot.rb
99
+ - lib/omniauth/wild_apricot.rb
100
+ - lib/omniauth/wild_apricot/version.rb
101
+ - omniauth-wild-apricot.gemspec
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/rocket-house/omniauth-wild-apricot
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '2.2'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.2.32
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A WildApricot OAuth2 strategy for OmniAuth 1.x
126
+ test_files: []