Skip to content

Commit

Permalink
Rename base_uri to api_url to fit with Authsignal convention (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenclouston authored Nov 25, 2024
1 parent da15137 commit 6473eab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ end

You can find your `api_secret_key` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).

You must specify the correct `baseUrl` for your tenant's region.
You must specify the correct `api_url` for your tenant's region.

| Region | Base URL |
| ----------- | ----------------------------------- |
| US (Oregon) | https://signal.authsignal.com/v1 |
| AU (Sydney) | https://au.signal.authsignal.com/v1 |
| EU (Dublin) | https://eu.signal.authsignal.com/v1 |

For example, to set the base URL to use our AU region:
For example, to set the API URL to use our AU region:

```
require 'authsignal'
Authsignal.setup do |config|
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
config.base_uri = "https://au.signal.authsignal.com/v1"
config.api_url = "https://au.signal.authsignal.com/v1"
# If you would like the Authsignal client to retry requests due to network issues
config.retry = true # default value: false
Expand Down
2 changes: 1 addition & 1 deletion lib/authsignal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(retry_options: RETRY_OPTIONS)
@api_key = require_api_key

@client = Faraday.new do |builder|
builder.url_prefix = Authsignal.configuration.base_uri
builder.url_prefix = Authsignal.configuration.api_url
builder.adapter :net_http
builder.request :authorization, :basic, @api_key, nil

Expand Down
4 changes: 2 additions & 2 deletions lib/authsignal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.config_option(name)
end

config_option :api_secret_key
config_option :base_uri
config_option :api_url
config_option :debug
config_option :retry

Expand All @@ -22,7 +22,7 @@ def initialize

# set default attribute values
@defaults = OpenStruct.new({
base_uri: 'https://signal.authsignal.com/v1/',
api_url: 'https://signal.authsignal.com/v1/',
retry: false,
debug: false
})
Expand Down
30 changes: 15 additions & 15 deletions spec/authsignal/authsignal_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe Authsignal do
let(:base_uri) { 'http://localhost:8080/v1' }
let(:api_url) { 'http://localhost:8080/v1' }

it "has a version number" do
expect(Authsignal::VERSION).not_to be nil
Expand All @@ -10,7 +10,7 @@
before do
Authsignal.setup do |config|
config.api_secret_key = 'secret'
config.base_uri = base_uri
config.api_url = api_url
end
end

Expand All @@ -20,7 +20,7 @@
let(:idempotency_key) { "f7f6ff4c-600f-4d61-99a2-b1157fe43777" }
let(:user_id) { 123 }
let(:action) { 'signIn' }
let(:url) { "#{base_uri}/users/#{user_id}/actions/#{action}" }
let(:url) { "#{api_url}/users/#{user_id}/actions/#{action}" }

it 'handles plain text' do
stub_request(:post, url)
Expand All @@ -36,7 +36,7 @@

describe ".get_user" do
it 'succeeds' do
stub_request(:get, "#{base_uri}/users/1")
stub_request(:get, "#{api_url}/users/1")
.with(basic_auth: ['secret', ''])
.to_return(body: {isEnrolled: false, url: "https://www.example.com", accessToken: "xxx"}.to_json,
status: 200,
Expand All @@ -51,7 +51,7 @@

describe ".update_user" do
it 'succeeds' do
stub_request(:post, "#{base_uri}/users/1")
stub_request(:post, "#{api_url}/users/1")
.with(basic_auth: ['secret', ''], body: { email: "[email protected]" })
.to_return(body: {userId: "1", email: "[email protected]"}.to_json,
status: 200,
Expand All @@ -66,7 +66,7 @@

describe ".delete_user" do
it 'succeeds' do
stub_request(:delete, "#{base_uri}/users/1")
stub_request(:delete, "#{api_url}/users/1")
.with(basic_auth: ['secret', ''])
.to_return(body: {success: true}.to_json,
status: 200,
Expand All @@ -93,7 +93,7 @@
recoveryCodes: ["xxxx"]
}

stub_request(:post, "#{base_uri}/users/1/authenticators")
stub_request(:post, "#{api_url}/users/1/authenticators")
.with(basic_auth: ['secret', ''])
.with(body: { oobChannel:"SMS",phoneNumber:"+64270000000" })
.to_return(body: payload.to_json,
Expand Down Expand Up @@ -121,7 +121,7 @@

describe ".delete_authenticator" do
it 'succeeds' do
stub_request(:delete, "#{base_uri}/users/1/authenticators/9b2cfd40-7df2-4658-852d-a0c3456e5a2e")
stub_request(:delete, "#{api_url}/users/1/authenticators/9b2cfd40-7df2-4658-852d-a0c3456e5a2e")
.with(basic_auth: ['secret', ''])
.to_return(body: {success: true}.to_json,
status: 200,
Expand All @@ -138,7 +138,7 @@
let(:idempotency_key) { "f7f6ff4c-600f-4d61-99a2-b1157fe43777" }
let(:user_id) { 123 }
let(:action) { 'signIn' }
let(:url) { "#{base_uri}/users/#{user_id}/actions/#{action}" }
let(:url) { "#{api_url}/users/#{user_id}/actions/#{action}" }

it 'succeeds' do
stub_request(:post, url)
Expand Down Expand Up @@ -203,7 +203,7 @@

describe ".get_action" do
it 'succeeds' do
stub_request(:get, "#{base_uri}/users/1/actions/testAction/15cac140-f639-48c5-92db-835ec8d3d144")
stub_request(:get, "#{api_url}/users/1/actions/testAction/15cac140-f639-48c5-92db-835ec8d3d144")
.with(basic_auth: ['secret', ''])
.to_return(body: {state: "ALLOW", ruleIds: [], stateUpdatedAt: "2022-07-25T03:19:00.316Z", createdAt: "2022-07-25T03:19:00.316Z"}.to_json,
status: 200,
Expand All @@ -228,7 +228,7 @@
let(:state) { "ALLOW" }

it "succeeds" do
stub_request(:patch, "#{base_uri}/users/#{user_id}/actions/#{action}/#{idempotency_key}")
stub_request(:patch, "#{api_url}/users/#{user_id}/actions/#{action}/#{idempotency_key}")
.with(
basic_auth: ['secret', ''],
headers: { 'Content-Type'=>'application/json' })
Expand All @@ -251,7 +251,7 @@

describe ".validate_challenge" do
it "Checks that the isValid is true when userId correct" do
stub_request(:post, "#{base_uri}/validate")
stub_request(:post, "#{api_url}/validate")
.with(
headers: {
'Content-Type'=>'application/json',
Expand Down Expand Up @@ -283,7 +283,7 @@
end

it "Checks that isValid is false when userId is incorrect" do
stub_request(:post, "#{base_uri}/validate")
stub_request(:post, "#{api_url}/validate")
.with(
headers: {
'Content-Type'=>'application/json',
Expand All @@ -310,7 +310,7 @@
end

it "Checks that isValid is false when action is invalid" do
stub_request(:post, "#{base_uri}/validate")
stub_request(:post, "#{api_url}/validate")
.with(
headers: {
'Content-Type'=>'application/json',
Expand All @@ -336,7 +336,7 @@
end

it "Checks that an error is thrown when an unknown error is returned from Authsignal" do
stub_request(:post, "#{base_uri}/validate")
stub_request(:post, "#{api_url}/validate")
.with(
headers: {
'Content-Type'=>'application/json',
Expand Down

0 comments on commit 6473eab

Please sign in to comment.