Skip to content

Commit

Permalink
feat!: remove deprecated methods (#157)
Browse files Browse the repository at this point in the history
feat!: update class constructor signatures
  • Loading branch information
ctran88 authored Jan 2, 2025
1 parent c49fe3a commit 111431e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 50 deletions.
15 changes: 3 additions & 12 deletions lib/passageidentity/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@
module Passage
# The Passage::Auth class provides methods for authenticating requests and tokens
class Auth
def initialize(app_id, api_key, auth_strategy)
@app_cache = ActiveSupport::Cache::MemoryStore.new
def initialize(app_id:, req_opts:)
@app_id = app_id
@api_key = api_key
@auth_strategy = auth_strategy
@req_opts = req_opts

@app_cache = ActiveSupport::Cache::MemoryStore.new
fetch_jwks

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']

@tokens_client = OpenapiClient::TokensApi.new
@magic_links_client = OpenapiClient::MagicLinksApi.new
end

Expand Down
43 changes: 16 additions & 27 deletions lib/passageidentity/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,35 @@

require_relative 'auth'
require_relative 'user_api'
require_relative 'error'
require_relative 'version'

module Passage
COOKIE_STRATEGY = 0
HEADER_STRATEGY = 1

EMAIL_CHANNEL = 'email'
PHONE_CHANNEL = 'phone'

# The Passage::Client class provides methods for interacting with Passage
class Client
attr_reader :auth, :user

def initialize(app_id:, api_key: '', auth_strategy: COOKIE_STRATEGY)
@app_id = app_id
@api_key = api_key

# check for valid auth strategy
unless [COOKIE_STRATEGY, HEADER_STRATEGY].include? auth_strategy
raise PassageError.new(
status_code: 400,
body: {
error: 'Invalid auth strategy',
code: 'invalid_argument'
}
)
def initialize(app_id:, api_key:)
unless app_id && !app_id.empty?
raise ArgumentError,
'A Passage App ID is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
end
unless api_key && !api_key.empty?
raise ArgumentError,
'A Passage API key is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
end

@auth_strategy = auth_strategy

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']
req_opts = {}
req_opts[:header_params] = {
'Passage-Version' => "passage-ruby #{Passage::VERSION}",
'Authorization' => "Bearer #{api_key}"
}
req_opts[:debug_auth_names] = ['header']

@auth = Passage::Auth.new(@app_id, @api_key, @auth_strategy)
@user = Passage::UserAPI.new(@app_id, @api_key)
@auth = Passage::Auth.new(app_id: app_id, req_opts: req_opts)
@user = Passage::UserAPI.new(app_id: app_id, req_opts: req_opts)
end
end
end
16 changes: 5 additions & 11 deletions lib/passageidentity/user_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ module Passage
# The UserAPI class provides methods for interacting with Passage Users
class UserAPI
# rubocop:disable Metrics/AbcSize
def initialize(app_id, api_key)
def initialize(app_id:, req_opts:)
@app_id = app_id
@api_key = api_key
@req_opts = req_opts

@user_client = OpenapiClient::UsersApi.new
@user_device_client = OpenapiClient::UserDevicesApi.new

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']
@tokens_client = OpenapiClient::TokensApi.new
end

def get(user_id:)
Expand Down Expand Up @@ -160,8 +155,7 @@ def revoke_refresh_tokens(user_id:)
raise ArgumentError, 'user_id is required.' unless user_id && !user_id.empty?

begin
tokens_client = OpenapiClient::TokensApi.new
tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
@tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
rescue Faraday::Error => e
raise PassageError.new(
status_code: e.response[:status],
Expand Down

0 comments on commit 111431e

Please sign in to comment.