Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
77 changes: 20 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,42 @@
<img width="1070" alt="Authsignal" src="https://raw.githubusercontent.com/authsignal/authsignal-php/main/.github/images/authsignal.png">

# Authsignal Server PHP SDK
# Authsignal PHP SDK

[![License](https://img.shields.io/packagist/l/authsignal/authsignal-php.svg)](https://github.com/authsignal/authsignal-php/blob/main/LICENSE)

The official Authsignal PHP library for server-side applications. Use this SDK to easily integrate Authsignal's multi-factor authentication (MFA) and passwordless features into your PHP backend.

## Installation

1. Add Authsignal's library to your project using Composer:

```bash
composer require authsignal/authsignal-php
```

2. Run `composer update` to install the dependencies.
3. Authsignal will now be autoloaded into your project.

## Initialization

Initialize the Authsignal SDK, ensuring you do not hard code the Authsignal Secret Key, always keep this safe.

```php
Authsignal::setApiSecretKey('secretKey');
Using Composer:
```bash
composer require authsignal/authsignal-php
```

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

## Region selection

Authsignal has multiple api hosting regions. To view your hostname for your tenant, find it in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).

| 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 |
## Getting Started

You can set the hostname via the following code. If the `setApiUrl` function is not called, the api call defaults to the main Authsignal US region hostname `https://signal.authsignal.com`

An example setting the client to use the AU region.
Initialize the Authsignal client with your secret key from the [Authsignal Portal](https://portal.authsignal.com/) and the API URL for your region.

```php
Authsignal::setApiUrl("https://au.signal.authsignal.com/v1");
```

Alternatively, an environment variable can be used to set the API URL:
use Authsignal;

```bash
AUTHSIGNAL_API_URL=https://au.signal.authsignal.com/v1
// Initialize the client
Authsignal::setApiSecretKey(getenv('AUTHSIGNAL_SECRET_KEY'));
Authsignal::setApiUrl(getenv('AUTHSIGNAL_API_URL')); // Use region-specific URL
```

## Usage

Authsignal's server side signal API has five main calls `track`, `getAction`, `getUser`, `enrollVerifiedAuthenticator`, `verifyChallenge`

For more details on these api calls, refer to our [official PHP SDK docs](https://docs.authsignal.com/sdks/server/php#trackaction).
### API URLs by Region

### Response & Error handling

Example:

```php
$result = Authsignal::updateAction(
userId: $userId,
action: $action,
idempotencyKey: "invalidKey",
attributes: ['state' => 'CHALLENGE_FAILED']
);

# PHP Fatal error: Uncaught AuthsignalNotFoundError: 404 - not_found
```
| Region | API URL |
| ----------- | -------------------------------- |
| US (Oregon) | https://api.authsignal.com/v1 |
| AU (Sydney) | https://au.api.authsignal.com/v1 |
| EU (Dublin) | https://eu.api.authsignal.com/v1 |

## License

The library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
This SDK is licensed under the [MIT License](LICENSE).

## Documentation

For more information and advanced usage examples, refer to the official [Authsignal Server-Side SDK documentation](https://docs.authsignal.com/sdks/server/overview).
For more information and advanced usage examples, refer to the official [Authsignal Server-Side SDK documentation](https://docs.authsignal.com/sdks/server/overview).
4 changes: 2 additions & 2 deletions lib/Authsignal/Authsignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

abstract class Authsignal
{
const VERSION = '4.2.0';
const VERSION = '4.3.0';

public static $apiSecretKey;
public static $webhook;

public static $apiUrl = 'https://signal.authsignal.com';
public static $apiUrl = 'https://api.authsignal.com';

private static $curlOpts = array();
private static $validCurlOpts = array(CURLOPT_CONNECTTIMEOUT,
Expand Down
2 changes: 1 addition & 1 deletion lib/Authsignal/AuthsignalRequestTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function send($method, $url, $payload) {
'Content-Type: application/json',
'Content-Length: ' . (is_null($body) ? 0 : strlen($body)),
'X-Authsignal-Version: ' . Authsignal::VERSION,
'User-Agent: Authsignal PHP'
'User-Agent: authsignal-php'
);
$curlOptions[CURLOPT_HEADER] = true;

Expand Down
Loading