authsignal-ruby 1.0.0 → 2.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 +4 -4
 - data/Gemfile +0 -2
 - data/Gemfile.lock +1 -3
 - data/lib/authsignal/client.rb +15 -0
 - data/lib/authsignal/version.rb +1 -1
 - data/lib/authsignal.rb +5 -29
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2abb851e23947d6e5e888a7b1773ee3b87eb3c21e121944ddd30b9b930edf315
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9966e065c8d7aa2da856fb95fcbde6db428809e02d72e3fba4659af105508164
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 898f6940954145afb4bbaaba817ffa66e3f4a336cb4e2bc1b87df32af0a1e9d354d93f1c6e0bdb8e82c47571734d7e04da7d0c81ef13300cfb14d47f7fe222ff
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2a07fdc089590b7d7cd6d8a5cb60d3ce5c94aa03923a6bf0e58b549ab40bf13484af0ac3787bc509f6d6d25f09301b760474b3d41d26719874d7f4062d896516
         
     | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                authsignal-ruby ( 
     | 
| 
      
 4 
     | 
    
         
            +
                authsignal-ruby (2.0.0)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  httparty (~> 0.21.0)
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            GEM
         
     | 
| 
         @@ -16,7 +16,6 @@ GEM 
     | 
|
| 
       16 
16 
     | 
    
         
             
                httparty (0.21.0)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  mini_mime (>= 1.0.0)
         
     | 
| 
       18 
18 
     | 
    
         
             
                  multi_xml (>= 0.5.2)
         
     | 
| 
       19 
     | 
    
         
            -
                jwt (2.7.1)
         
     | 
| 
       20 
19 
     | 
    
         
             
                mini_mime (1.1.5)
         
     | 
| 
       21 
20 
     | 
    
         
             
                multi_xml (0.6.0)
         
     | 
| 
       22 
21 
     | 
    
         
             
                public_suffix (4.0.7)
         
     | 
| 
         @@ -45,7 +44,6 @@ PLATFORMS 
     | 
|
| 
       45 
44 
     | 
    
         | 
| 
       46 
45 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       47 
46 
     | 
    
         
             
              authsignal-ruby!
         
     | 
| 
       48 
     | 
    
         
            -
              jwt
         
     | 
| 
       49 
47 
     | 
    
         
             
              rake (~> 13.0)
         
     | 
| 
       50 
48 
     | 
    
         
             
              rspec (~> 3.2)
         
     | 
| 
       51 
49 
     | 
    
         
             
              webmock (~> 3.14.0)
         
     | 
    
        data/lib/authsignal/client.rb
    CHANGED
    
    | 
         @@ -4,6 +4,13 @@ module Authsignal 
     | 
|
| 
       4 
4 
     | 
    
         
             
                    NO_API_KEY_MESSAGE  = "No Authsignal API Secret Key Set"
         
     | 
| 
       5 
5 
     | 
    
         
             
                    include HTTParty
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
                    def handle_response(response)
         
     | 
| 
      
 8 
     | 
    
         
            +
                        unless response.success?
         
     | 
| 
      
 9 
     | 
    
         
            +
                          raise HTTParty::ResponseError, "Failed with status code #{response.code}"
         
     | 
| 
      
 10 
     | 
    
         
            +
                        end
         
     | 
| 
      
 11 
     | 
    
         
            +
                        response
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       7 
14 
     | 
    
         
             
                    def initialize
         
     | 
| 
       8 
15 
     | 
    
         
             
                        self.class.base_uri Authsignal.configuration.base_uri
         
     | 
| 
       9 
16 
     | 
    
         
             
                        @api_key = require_api_key
         
     | 
| 
         @@ -37,6 +44,14 @@ module Authsignal 
     | 
|
| 
       37 
44 
     | 
    
         
             
                        get(path)
         
     | 
| 
       38 
45 
     | 
    
         
             
                    end
         
     | 
| 
       39 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                    def validate_challenge(user_id: nil, token:)
         
     | 
| 
      
 48 
     | 
    
         
            +
                        path = "/validate"
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                        response = post(path, query: {}, body: { userId: user_id, token: token }.to_json)
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                        handle_response(response)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       40 
55 
     | 
    
         
             
                    def get_action(user_id, action_code, idempotency_key)
         
     | 
| 
       41 
56 
     | 
    
         
             
                        get("/users/#{ERB::Util.url_encode(user_id)}/actions/#{action_code}/#{ERB::Util.url_encode(idempotency_key)}")
         
     | 
| 
       42 
57 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/authsignal/version.rb
    CHANGED
    
    
    
        data/lib/authsignal.rb
    CHANGED
    
    | 
         @@ -1,5 +1,4 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "httparty"
         
     | 
| 
       2 
     | 
    
         
            -
            require 'jwt'
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            require "authsignal/version"
         
     | 
| 
       5 
4 
     | 
    
         
             
            require "authsignal/client"
         
     | 
| 
         @@ -65,34 +64,11 @@ module Authsignal 
     | 
|
| 
       65 
64 
     | 
    
         
             
                        false
         
     | 
| 
       66 
65 
     | 
    
         
             
                    end
         
     | 
| 
       67 
66 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                    def validate_challenge( 
     | 
| 
       69 
     | 
    
         
            -
                         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                        end
         
     | 
| 
       74 
     | 
    
         
            -
                      
         
     | 
| 
       75 
     | 
    
         
            -
                        decoded_user_id = decoded_token["other"]["userId"]
         
     | 
| 
       76 
     | 
    
         
            -
                        action_code = decoded_token["other"]["actionCode"]
         
     | 
| 
       77 
     | 
    
         
            -
                        idempotency_key = decoded_token["other"]["idempotencyKey"]
         
     | 
| 
       78 
     | 
    
         
            -
                      
         
     | 
| 
       79 
     | 
    
         
            -
                        if user_id && user_id != decoded_user_id
         
     | 
| 
       80 
     | 
    
         
            -
                          return { user_id: decoded_user_id, success: false, state: nil }
         
     | 
| 
       81 
     | 
    
         
            -
                        end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                        if action_code && idempotency_key
         
     | 
| 
       84 
     | 
    
         
            -
                          action_result = get_action(user_id: decoded_user_id, action_code: action_code, idempotency_key: idempotency_key)
         
     | 
| 
       85 
     | 
    
         
            -
                      
         
     | 
| 
       86 
     | 
    
         
            -
                          if action_result
         
     | 
| 
       87 
     | 
    
         
            -
                            state = action_result[:state]
         
     | 
| 
       88 
     | 
    
         
            -
                            success = state == "CHALLENGE_SUCCEEDED"
         
     | 
| 
       89 
     | 
    
         
            -
                      
         
     | 
| 
       90 
     | 
    
         
            -
                            return { user_id: decoded_user_id, success: success, state: state, action: action_code }
         
     | 
| 
       91 
     | 
    
         
            -
                          end
         
     | 
| 
       92 
     | 
    
         
            -
                        end
         
     | 
| 
       93 
     | 
    
         
            -
                      
         
     | 
| 
       94 
     | 
    
         
            -
                        { user_id: decoded_user_id, success: false, state: nil }
         
     | 
| 
       95 
     | 
    
         
            -
                      end
         
     | 
| 
      
 67 
     | 
    
         
            +
                    def validate_challenge(token:, user_id: nil)
         
     | 
| 
      
 68 
     | 
    
         
            +
                        response = Client.new.validate_challenge(user_id: user_id, token: token)
         
     | 
| 
      
 69 
     | 
    
         
            +
                        
         
     | 
| 
      
 70 
     | 
    
         
            +
                        return { user_id: response["userId"], is_valid: response["isValid"], state: response["state"], action: response["actionCode"] }
         
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
       96 
72 
     | 
    
         | 
| 
       97 
73 
     | 
    
         
             
                    private
         
     | 
| 
       98 
74 
     | 
    
         
             
                    def underscore(string)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: authsignal-ruby
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - justinsoong
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-04-15 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: httparty
         
     | 
| 
         @@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       109 
109 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       110 
110 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       111 
111 
     | 
    
         
             
            requirements: []
         
     | 
| 
       112 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 112 
     | 
    
         
            +
            rubygems_version: 3.5.3
         
     | 
| 
       113 
113 
     | 
    
         
             
            signing_key:
         
     | 
| 
       114 
114 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       115 
115 
     | 
    
         
             
            summary: The Authsignal ruby server side signal API.
         
     |