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
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Validate Composer manifest and lock
run: composer validate --no-check-publish --no-interaction

- name: Audit locked dependencies
run: composer audit --locked --no-interaction

- name: Install locked dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-scripts

Expand Down
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,85 @@
<img src="https://img.shields.io/github/license/Triangle-org/OAuth?label=%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F" alt="Лицензия">
</a>
</p>

## Совместимость

- PHP 8.2 или новее.
- Triangle Engine `^9.0` и Localzet HTTP Client `^3.0`; эта ветка рассчитана на Localzet Server 7.

## Установка

```sh
composer require triangle/oauth
```

Добавьте провайдера в конфигурацию Triangle Engine:

```php
$oauth = new \Triangle\OAuth([
'providers' => [
'google' => [
'enabled' => true,
'callback' => 'https://app.example.com/oauth/google/callback',
'keys' => [
'id' => getenv('GOOGLE_CLIENT_ID'),
'secret' => getenv('GOOGLE_CLIENT_SECRET'),
],
],
],
]);

$result = $oauth->authenticate('google');
if ($result instanceof \Triangle\Engine\Response) {
return $result; // Redirect the browser to the provider.
}

$profile = $result->getUserProfile();
```

Если передать HTTP-клиент явно через конструктор адаптера или `setHttpClient()`, будет использован именно он; `http_client_options` применяется, когда адаптер создаёт клиент самостоятельно.

`authenticate()` returns an Engine response while starting authorization and the provider adapter after authentication. Keep client secrets in environment configuration. Provider-specific options and examples are in the [Triangle OAuth documentation](https://docs.localzet.com/triangle/oauth).

For HTTP client settings, use the provider option `http_client_options` supported by Localzet HTTP Client 3, for example `['timeout' => 10]` or a TLS `context`. The old `curl_options` setting is unsupported by HTTP Client 3.

An HTTP client passed explicitly to an adapter constructor or `setHttpClient()` is used as-is. `http_client_options` applies when the adapter creates its own client.

## Compatibility

- PHP 8.2 or newer.
- Triangle Engine `^9.0` and Localzet HTTP Client `^3.0`; this branch targets Localzet Server 7.

## Installation

```sh
composer require triangle/oauth
```

Add a provider to your Triangle Engine configuration:

```php
$oauth = new \Triangle\OAuth([
'providers' => [
'google' => [
'enabled' => true,
'callback' => 'https://app.example.com/oauth/google/callback',
'keys' => [
'id' => getenv('GOOGLE_CLIENT_ID'),
'secret' => getenv('GOOGLE_CLIENT_SECRET'),
],
],
],
]);

$result = $oauth->authenticate('google');
if ($result instanceof \Triangle\Engine\Response) {
return $result; // Redirect the browser to the provider.
}

$profile = $result->getUserProfile();
```

`authenticate()` returns an Engine response to start authorization and the provider adapter after authentication. Keep client secrets in environment configuration. See the [Triangle OAuth documentation](https://docs.localzet.com/triangle/oauth) for provider-specific options and examples.

Use the provider option `http_client_options` for Localzet HTTP Client 3, such as `['timeout' => 10]` or TLS `context` settings. The old `curl_options` option is not supported by HTTP Client 3.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"ext-mbstring": "*",
"ext-json": "*",
"ext-curl": "*",
"localzet/http": "^2.0",
"triangle/engine": "^8.1"
"localzet/http": "^3.0",
"triangle/engine": "^9.0"
},
"suggest": {
"ext-libxml": "Требуется для провайдера Steam",
Expand All @@ -54,6 +54,9 @@
"Triangle\\": "src"
}
},
"scripts": {
"test": "php tests/oauth_authenticate_redirect.php"
},
"config": {
"platform": {
"php": "8.2.0"
Expand Down
Loading