zaikio-oauth_client 0.4.0 → 0.5.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 +4 -4
 - data/README.md +13 -12
 - data/app/models/zaikio/access_token.rb +7 -7
 - data/lib/zaikio/oauth_client.rb +1 -1
 - data/lib/zaikio/oauth_client/configuration.rb +1 -1
 - data/lib/zaikio/oauth_client/version.rb +1 -1
 - metadata +8 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5423f9566cab7cd383ea7f42fa86c7a899e615be78eb3bf0f374a23742df8106
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5a2b07e3def1d7d55730767b1145265782d9bcde45fabbddace0ebd783c33915
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b5e9767b1c46ec96fe4ee6d12efd1b5090f0d032b3e651f2f941ce3ccae5a4151373ba1208a9c169f668cd2452c9701376989848a1465063fb731359d066e3b1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d14fb1595c1ae862873d4c38fc4ef6cd41b1f29088accca024d59f14f83e628fc91dcf7c70be64d9ccf62ca840c97125720c6b7d8c1873105e51d3b192779fda
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -60,7 +60,7 @@ Zaikio::OAuthClient.configure do |config| 
     | 
|
| 
       60 
60 
     | 
    
         
             
              end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
              config.around_auth do |access_token, block|
         
     | 
| 
       63 
     | 
    
         
            -
                Zaikio:: 
     | 
| 
      
 63 
     | 
    
         
            +
                Zaikio::Hub.with_token(access_token.token) do
         
     | 
| 
       64 
64 
     | 
    
         
             
                  block.call(access_token)
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         
             
              end
         
     | 
| 
         @@ -93,7 +93,7 @@ Configure sidekiq scheduler in `config/sidekiq.yml`: 
     | 
|
| 
       93 
93 
     | 
    
         | 
| 
       94 
94 
     | 
    
         
             
            ### OAuth Flow
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
            From any point in your application you can start using the Zaikio  
     | 
| 
      
 96 
     | 
    
         
            +
            From any point in your application you can start using the Zaikio Hub OAuth2 flow with
         
     | 
| 
       97 
97 
     | 
    
         | 
| 
       98 
98 
     | 
    
         
             
            ```rb
         
     | 
| 
       99 
99 
     | 
    
         
             
            redirect_to zaikio_oauth_client.new_session_path
         
     | 
| 
         @@ -109,10 +109,10 @@ This will redirect the user to the OAuth Authorize endpoint of the Zaikio Direct 
     | 
|
| 
       109 
109 
     | 
    
         | 
| 
       110 
110 
     | 
    
         
             
            The Zaikio gem engine will set a cookie for the user after a successful OAuth flow: `cookies.encrypted[:zaikio_person_id]`.
         
     | 
| 
       111 
111 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
            If you are using for example `Zaikio:: 
     | 
| 
      
 112 
     | 
    
         
            +
            If you are using for example `Zaikio::Hub::Models`, you can use this snippet to set the current user:
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
            ```ruby
         
     | 
| 
       115 
     | 
    
         
            -
            Current.user ||= Zaikio:: 
     | 
| 
      
 115 
     | 
    
         
            +
            Current.user ||= Zaikio::Hub::Models::Person.find_by(id: cookies.encrypted[:zaikio_person_id])
         
     | 
| 
       116 
116 
     | 
    
         
             
            ````
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
            You can then use `Current.user` anywhere.
         
     | 
| 
         @@ -149,7 +149,7 @@ class ApplicationController < ActionController::Base 
     | 
|
| 
       149 
149 
     | 
    
         
             
                cookies.encrypted[:zaikio_person_id] = access_token.bearer_id unless access_token.organization?
         
     | 
| 
       150 
150 
     | 
    
         | 
| 
       151 
151 
     | 
    
         
             
                # Sync data on login
         
     | 
| 
       152 
     | 
    
         
            -
                Zaikio:: 
     | 
| 
      
 152 
     | 
    
         
            +
                Zaikio::Hub.with_token(access_token.token) do
         
     | 
| 
       153 
153 
     | 
    
         
             
                  access_token.bearer_klass.find_and_reload!(access_token.bearer_id, includes: :all)
         
     | 
| 
       154 
154 
     | 
    
         
             
                end
         
     | 
| 
       155 
155 
     | 
    
         | 
| 
         @@ -234,14 +234,15 @@ If you use the provided OAuth credentials from above and test this against the S 
     | 
|
| 
       234 
234 
     | 
    
         | 
| 
       235 
235 
     | 
    
         
             
            **Make sure you have the dummy app running locally to validate your changes.**
         
     | 
| 
       236 
236 
     | 
    
         | 
| 
       237 
     | 
    
         
            -
            Make your changes and  
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
            **To push a new release:**
         
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
            - `gem build zaikio-oauth_client.gemspec`
         
     | 
| 
       242 
     | 
    
         
            -
            - `gem push zaikio-oauth_client-0.1.0.gem`
         
     | 
| 
       243 
     | 
    
         
            -
            *Adjust the version accordingly.*
         
     | 
| 
      
 237 
     | 
    
         
            +
            - Make your changes and submit a pull request for them
         
     | 
| 
      
 238 
     | 
    
         
            +
            - Make sure to update `CHANGELOG.md`
         
     | 
| 
       244 
239 
     | 
    
         | 
| 
      
 240 
     | 
    
         
            +
            To release a new version of the gem:
         
     | 
| 
      
 241 
     | 
    
         
            +
            - Update the version in `lib/zaikio/oauth_client/version.rb`
         
     | 
| 
      
 242 
     | 
    
         
            +
            - Update `CHANGELOG.md` to include the new version and its release date
         
     | 
| 
      
 243 
     | 
    
         
            +
            - Commit and push your changes
         
     | 
| 
      
 244 
     | 
    
         
            +
            - Create a [new release on GitHub](https://github.com/zaikio/zaikio-directory-models/releases/new)
         
     | 
| 
      
 245 
     | 
    
         
            +
            - CircleCI will build the Gem package and push it Rubygems for you
         
     | 
| 
       245 
246 
     | 
    
         | 
| 
       246 
247 
     | 
    
         
             
            ## License
         
     | 
| 
       247 
248 
     | 
    
         | 
| 
         @@ -26,7 +26,7 @@ module Zaikio 
     | 
|
| 
       26 
26 
     | 
    
         
             
                # Scopes
         
     | 
| 
       27 
27 
     | 
    
         
             
                scope :valid, lambda {
         
     | 
| 
       28 
28 
     | 
    
         
             
                  where("expires_at > :now", now: Time.current)
         
     | 
| 
       29 
     | 
    
         
            -
                    .where.not(id: Zaikio::JWTAuth. 
     | 
| 
      
 29 
     | 
    
         
            +
                    .where.not(id: Zaikio::JWTAuth.revoked_token_ids)
         
     | 
| 
       30 
30 
     | 
    
         
             
                }
         
     | 
| 
       31 
31 
     | 
    
         
             
                scope :with_invalid_refresh_token, lambda {
         
     | 
| 
       32 
32 
     | 
    
         
             
                  where("created_at <= ?", Time.current - Zaikio::AccessToken.refresh_token_valid_for)
         
     | 
| 
         @@ -36,15 +36,15 @@ module Zaikio 
     | 
|
| 
       36 
36 
     | 
    
         
             
                        now: Time.current,
         
     | 
| 
       37 
37 
     | 
    
         
             
                        created_at_max: Time.current - refresh_token_valid_for)
         
     | 
| 
       38 
38 
     | 
    
         
             
                    .where("refresh_token IS NOT NULL")
         
     | 
| 
       39 
     | 
    
         
            -
                    .where.not(id: Zaikio::JWTAuth. 
     | 
| 
      
 39 
     | 
    
         
            +
                    .where.not(id: Zaikio::JWTAuth.revoked_token_ids)
         
     | 
| 
       40 
40 
     | 
    
         
             
                }
         
     | 
| 
       41 
     | 
    
         
            -
                scope :by_bearer, lambda { | 
     | 
| 
      
 41 
     | 
    
         
            +
                scope :by_bearer, lambda { |bearer_id:, scopes: [], bearer_type: "Person"|
         
     | 
| 
       42 
42 
     | 
    
         
             
                  where(bearer_type: bearer_type, bearer_id: bearer_id)
         
     | 
| 
       43 
43 
     | 
    
         
             
                    .where("scopes @> ARRAY[?]::varchar[]", scopes)
         
     | 
| 
       44 
44 
     | 
    
         
             
                }
         
     | 
| 
       45 
45 
     | 
    
         
             
                scope :usable, lambda { |options|
         
     | 
| 
       46 
     | 
    
         
            -
                  by_bearer(options).valid.or(by_bearer(options).valid_refresh)
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
                  by_bearer(**options).valid.or(by_bearer(**options).valid_refresh)
         
     | 
| 
      
 47 
     | 
    
         
            +
                                      .order(expires_at: :desc)
         
     | 
| 
       48 
48 
     | 
    
         
             
                }
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                def expired?
         
     | 
| 
         @@ -62,8 +62,8 @@ module Zaikio 
     | 
|
| 
       62 
62 
     | 
    
         
             
                def bearer_klass
         
     | 
| 
       63 
63 
     | 
    
         
             
                  return unless Zaikio.const_defined?("Directory::Models")
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
                  if Zaikio:: 
     | 
| 
       66 
     | 
    
         
            -
                    Zaikio:: 
     | 
| 
      
 65 
     | 
    
         
            +
                  if Zaikio::Hub::Models.configuration.respond_to?(:"#{bearer_type.underscore}_class_name")
         
     | 
| 
      
 66 
     | 
    
         
            +
                    Zaikio::Hub::Models.configuration.public_send(:"#{bearer_type.underscore}_class_name").constantize
         
     | 
| 
       67 
67 
     | 
    
         
             
                  else
         
     | 
| 
       68 
68 
     | 
    
         
             
                    "Zaikio::#{bearer_type}".constantize
         
     | 
| 
       69 
69 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/zaikio/oauth_client.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: zaikio-oauth_client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.5.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Zaikio GmbH
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-02-12 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -47,7 +47,7 @@ dependencies: 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    version: 0.2.1
         
     | 
| 
       48 
48 
     | 
    
         
             
                - - "<"
         
     | 
| 
       49 
49 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       50 
     | 
    
         
            -
                    version: 0. 
     | 
| 
      
 50 
     | 
    
         
            +
                    version: 0.5.0
         
     | 
| 
       51 
51 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       52 
52 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       53 
53 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -57,7 +57,7 @@ dependencies: 
     | 
|
| 
       57 
57 
     | 
    
         
             
                    version: 0.2.1
         
     | 
| 
       58 
58 
     | 
    
         
             
                - - "<"
         
     | 
| 
       59 
59 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       60 
     | 
    
         
            -
                    version: 0. 
     | 
| 
      
 60 
     | 
    
         
            +
                    version: 0.5.0
         
     | 
| 
       61 
61 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       62 
62 
     | 
    
         
             
              name: pg
         
     | 
| 
       63 
63 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -119,10 +119,11 @@ files: 
     | 
|
| 
       119 
119 
     | 
    
         
             
            - lib/zaikio/oauth_client/engine.rb
         
     | 
| 
       120 
120 
     | 
    
         
             
            - lib/zaikio/oauth_client/test_helper.rb
         
     | 
| 
       121 
121 
     | 
    
         
             
            - lib/zaikio/oauth_client/version.rb
         
     | 
| 
       122 
     | 
    
         
            -
            homepage: https:// 
     | 
| 
      
 122 
     | 
    
         
            +
            homepage: https://github.com/zaikio/zaikio-oauth_client
         
     | 
| 
       123 
123 
     | 
    
         
             
            licenses:
         
     | 
| 
       124 
124 
     | 
    
         
             
            - MIT
         
     | 
| 
       125 
     | 
    
         
            -
            metadata: 
     | 
| 
      
 125 
     | 
    
         
            +
            metadata:
         
     | 
| 
      
 126 
     | 
    
         
            +
              changelog_uri: https://github.com/zaikio/zaikio-oauth_client/blob/master/CHANGELOG.md
         
     | 
| 
       126 
127 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       127 
128 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       128 
129 
     | 
    
         
             
            require_paths:
         
     | 
| 
         @@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       138 
139 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       139 
140 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       140 
141 
     | 
    
         
             
            requirements: []
         
     | 
| 
       141 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 142 
     | 
    
         
            +
            rubygems_version: 3.2.3
         
     | 
| 
       142 
143 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       143 
144 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       144 
145 
     | 
    
         
             
            summary: Zaikio Platform Connectivity
         
     |