|
1 | 1 | <img width="1070" alt="Authsignal" src="https://raw.githubusercontent.com/authsignal/authsignal-php/main/.github/images/authsignal.png"> |
2 | 2 |
|
3 | | -# Authsignal Server PHP SDK |
| 3 | +# Authsignal PHP SDK |
| 4 | + |
| 5 | +[](https://github.com/authsignal/authsignal-php/blob/main/LICENSE) |
4 | 6 |
|
5 | 7 | 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. |
6 | 8 |
|
7 | 9 | ## Installation |
8 | 10 |
|
9 | | -1. Add Authsignal's library to your project using Composer: |
10 | | - |
11 | | - ```bash |
12 | | - composer require authsignal/authsignal-php |
13 | | - ``` |
14 | | - |
15 | | -2. Run `composer update` to install the dependencies. |
16 | | -3. Authsignal will now be autoloaded into your project. |
17 | | - |
18 | | -## Initialization |
19 | | - |
20 | | -Initialize the Authsignal SDK, ensuring you do not hard code the Authsignal Secret Key, always keep this safe. |
21 | | - |
22 | | -```php |
23 | | -Authsignal::setApiSecretKey('secretKey'); |
| 11 | +Using Composer: |
| 12 | +```bash |
| 13 | +composer require authsignal/authsignal-php |
24 | 14 | ``` |
25 | 15 |
|
26 | | -You can find your `secretKey` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api). |
27 | | - |
28 | | -## Region selection |
29 | | - |
30 | | -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). |
31 | | - |
32 | | -| Region | Base URL | |
33 | | -| ----------- | ----------------------------------- | |
34 | | -| US (Oregon) | https://signal.authsignal.com/v1 | |
35 | | -| AU (Sydney) | https://au.signal.authsignal.com/v1 | |
36 | | -| EU (Dublin) | https://eu.signal.authsignal.com/v1 | |
| 16 | +## Getting Started |
37 | 17 |
|
38 | | -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` |
39 | | - |
40 | | -An example setting the client to use the AU region. |
| 18 | +Initialize the Authsignal client with your secret key from the [Authsignal Portal](https://portal.authsignal.com/) and the API URL for your region. |
41 | 19 |
|
42 | 20 | ```php |
43 | | -Authsignal::setApiUrl("https://au.signal.authsignal.com/v1"); |
44 | | -``` |
45 | | - |
46 | | -Alternatively, an environment variable can be used to set the API URL: |
| 21 | +use Authsignal; |
47 | 22 |
|
48 | | -```bash |
49 | | -AUTHSIGNAL_API_URL=https://au.signal.authsignal.com/v1 |
| 23 | +// Initialize the client |
| 24 | +Authsignal::setApiSecretKey(getenv('AUTHSIGNAL_SECRET_KEY')); |
| 25 | +Authsignal::setApiUrl(getenv('AUTHSIGNAL_API_URL')); // Use region-specific URL |
50 | 26 | ``` |
51 | 27 |
|
52 | | -## Usage |
53 | | - |
54 | | -Authsignal's server side signal API has five main calls `track`, `getAction`, `getUser`, `enrollVerifiedAuthenticator`, `verifyChallenge` |
55 | | - |
56 | | -For more details on these api calls, refer to our [official PHP SDK docs](https://docs.authsignal.com/sdks/server/php#trackaction). |
| 28 | +### API URLs by Region |
57 | 29 |
|
58 | | -### Response & Error handling |
59 | | - |
60 | | -Example: |
61 | | - |
62 | | -```php |
63 | | -$result = Authsignal::updateAction( |
64 | | - userId: $userId, |
65 | | - action: $action, |
66 | | - idempotencyKey: "invalidKey", |
67 | | - attributes: ['state' => 'CHALLENGE_FAILED'] |
68 | | -); |
69 | | - |
70 | | -# PHP Fatal error: Uncaught AuthsignalNotFoundError: 404 - not_found |
71 | | -``` |
| 30 | +| Region | API URL | |
| 31 | +| ----------- | -------------------------------- | |
| 32 | +| US (Oregon) | https://api.authsignal.com/v1 | |
| 33 | +| AU (Sydney) | https://au.api.authsignal.com/v1 | |
| 34 | +| EU (Dublin) | https://eu.api.authsignal.com/v1 | |
72 | 35 |
|
73 | 36 | ## License |
74 | 37 |
|
75 | | -The library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
| 38 | +This SDK is licensed under the [MIT License](LICENSE). |
76 | 39 |
|
77 | 40 | ## Documentation |
78 | 41 |
|
79 | | -For more information and advanced usage examples, refer to the official [Authsignal Server-Side SDK documentation](https://docs.authsignal.com/sdks/server/overview). |
| 42 | +For more information and advanced usage examples, refer to the official [Authsignal Server-Side SDK documentation](https://docs.authsignal.com/sdks/server/overview). |
0 commit comments