Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ on:
pull_request:

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop

test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
Expand All @@ -19,11 +30,11 @@ jobs:
AUTHSIGNAL_API_URL: ${{ secrets.AUTHSIGNAL_API_URL }}
AUTHSIGNAL_API_SECRET_KEY: ${{ secrets.AUTHSIGNAL_API_SECRET_KEY }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ Metrics/BlockLength:
Metrics/ParameterLists:
Max: 15

# SDK classes can be longer
# SDK classes/modules can be longer
Metrics/ClassLength:
Max: 250

Metrics/ModuleLength:
Max: 150

Metrics/MethodLength:
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.10
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
authsignal-ruby (5.2.2)
authsignal-ruby (5.3.0)
base64
faraday (>= 2.0.1)
faraday-retry (~> 2.2)
Expand Down
66 changes: 66 additions & 0 deletions lib/authsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def get_user(user_id:)
handle_response(response)
end

def query_users(**options)
response = Client.new.query_users(**options)

handle_response(response)
end

def update_user(user_id:, attributes:)
response = Client.new.update_user(user_id: user_id, attributes: attributes)

Expand Down Expand Up @@ -86,12 +92,72 @@ def get_action(user_id:, action:, idempotency_key:)
handle_response(response)
end

def query_user_actions(user_id:, **options)
response = Client.new.query_user_actions(user_id: user_id, **options)

handle_response(response)
end

def update_action(user_id:, action:, idempotency_key:, attributes:)
response = Client.new.update_action(user_id: user_id, action: action, idempotency_key: idempotency_key, attributes: attributes)

handle_response(response)
end

def challenge(verification_method:, action:, **options)
response = Client.new.challenge(verification_method: verification_method, action: action, **options)

handle_response(response)
end

def verify(challenge_id:, verification_code:)
response = Client.new.verify(challenge_id: challenge_id, verification_code: verification_code)

handle_response(response)
end

def claim_challenge(challenge_id:, user_id:, **options)
response = Client.new.claim_challenge(challenge_id: challenge_id, user_id: user_id, **options)

handle_response(response)
end

def get_challenge(**options)
response = Client.new.get_challenge(**options)

handle_response(response)
end

def create_session(client_id:, token:, action: nil)
response = Client.new.create_session(client_id: client_id, token: token, action: action)

handle_response(response)
end

def validate_session(access_token:, client_ids: nil)
response = Client.new.validate_session(access_token: access_token, client_ids: client_ids)

handle_response(response)
end

def refresh_session(refresh_token:)
response = Client.new.refresh_session(refresh_token: refresh_token)

handle_response(response)
end

def revoke_session(access_token:)
response = Client.new.revoke_session(access_token: access_token)

handle_response(response)
end

def revoke_user_sessions(user_id:)
response = Client.new.revoke_user_sessions(user_id: user_id)

handle_response(response)
end

private

def handle_response(response)
Expand Down
150 changes: 150 additions & 0 deletions lib/authsignal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ def delete_user(user_id:)
make_request(:delete, "users/#{url_encode(user_id)}")
end

def query_users(
username: nil,
email: nil,
phone_number: nil,
token: nil,
limit: nil,
last_evaluated_user_id: nil
)
params = {
username: username,
email: email,
phoneNumber: phone_number,
token: token,
limit: limit&.to_s,
lastEvaluatedUserId: last_evaluated_user_id
}.compact

path = params.empty? ? 'users' : "users?#{URI.encode_www_form(params)}"
make_request(:get, path)
end

def get_authenticators(user_id:)
make_request(:get, "users/#{url_encode(user_id)}/authenticators")
end
Expand Down Expand Up @@ -81,10 +102,139 @@ def get_action(user_id:, action:, idempotency_key:)
make_request(:get, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}")
end

def query_user_actions(
user_id:,
from_date: nil,
action_codes: [],
state: nil
)
params = {
fromDate: from_date,
codes: action_codes.empty? ? nil : action_codes.join(','),
state: state
}.compact

base_path = "users/#{url_encode(user_id)}/actions"
path = params.empty? ? base_path : "#{base_path}?#{URI.encode_www_form(params)}"
make_request(:get, path)
end

def update_action(user_id:, action:, idempotency_key:, attributes:)
make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: attributes)
end

def challenge(
verification_method:,
action:,
idempotency_key: nil,
user_id: nil,
email: nil,
phone_number: nil,
sms_channel: nil,
locale: nil,
device_id: nil,
ip_address: nil,
user_agent: nil,
custom: nil,
scope: nil
)
body = {
verification_method: verification_method,
action: action,
idempotency_key: idempotency_key,
user_id: user_id,
email: email,
phone_number: phone_number,
sms_channel: sms_channel,
locale: locale,
device_id: device_id,
ip_address: ip_address,
user_agent: user_agent,
custom: custom,
scope: scope
}
make_request(:post, 'challenge', body: body)
end

def verify(challenge_id:, verification_code:)
body = {
challenge_id: challenge_id,
verification_code: verification_code
}
make_request(:post, 'verify', body: body)
end

def claim_challenge(
challenge_id:,
user_id:,
skip_verification_check: nil,
device_id: nil,
ip_address: nil,
user_agent: nil,
custom: nil
)
body = {
challenge_id: challenge_id,
user_id: user_id,
skip_verification_check: skip_verification_check,
device_id: device_id,
ip_address: ip_address,
user_agent: user_agent,
custom: custom
}
make_request(:post, 'claim', body: body)
end

def get_challenge(
challenge_id: nil,
user_id: nil,
action: nil,
verification_method: nil
)
params = {}
params[:challengeId] = challenge_id if challenge_id
params[:userId] = user_id if user_id
params[:action] = action if action
params[:verificationMethod] = verification_method if verification_method

query_string = URI.encode_www_form(params) unless params.empty?
path = query_string ? "challenges?#{query_string}" : 'challenges'

make_request(:get, path)
end

def create_session(client_id:, token:, action: nil)
body = {
client_id: client_id,
token: token,
action: action
}.compact
make_request(:post, 'sessions', body: body)
end

def validate_session(access_token:, client_ids: nil)
body = {
access_token: access_token,
client_ids: client_ids
}.compact
make_request(:post, 'sessions/validate', body: body)
end

def refresh_session(refresh_token:)
body = { refresh_token: refresh_token }
make_request(:post, 'sessions/refresh', body: body)
end

def revoke_session(access_token:)
body = { access_token: access_token }
make_request(:post, 'sessions/revoke', body: body)
end

def revoke_user_sessions(user_id:)
body = { user_id: user_id }
make_request(:post, 'sessions/user/revoke', body: body)
end

##
# TODO: delete identify?
def identify(user_id, user_payload)
Expand Down
2 changes: 1 addition & 1 deletion lib/authsignal/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Authsignal
VERSION = '5.2.2'
VERSION = '5.3.0'
end
Loading