Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
luizcmarin committed May 8, 2024
1 parent 07bf5e8 commit 796e66b
Show file tree
Hide file tree
Showing 30 changed files with 806 additions and 44 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Yii Framework authentication client extension Change Log
# Yii Framework External Authentication Extension Change Log

1.1.0 under development
-----------------------
## 1.1.0 under development

- Initial release.
57 changes: 19 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="80px">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px">
</a>
<a href="https://oauth.net/2/" target="_blank">
<img src="https://oauth.net/images/oauth-2-sm.png" height="80px">
Expand All @@ -12,13 +12,6 @@
<br>
</p>

This extension adds [OAuth](https://oauth.net/), [OAuth2](https://oauth.net/2/) and [OpenId Connect](https://openid.net/connect/)
consumers for the [Yii framework](https://www.yiiframework.com).

For license information check the [LICENSE](https://github.com/yiisoft/yii-auth-client/blob/master/LICENSE.md)-file.

Documentation is at [docs/guide/README.md](https://github.com/yiisoft/yii-auth-client/blob/master/docs/guide/README.md).

[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii-auth-client/v/stable.png)](https://packagist.org/packages/yiisoft/yii-auth-client)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii-auth-client/downloads.png)](https://packagist.org/packages/yiisoft/yii-auth-client)
[![Build status](https://github.com/yiisoft/yii-auth-client/workflows/build/badge.svg)](https://github.com/yiisoft/yii-auth-client/actions?query=workflow%3Abuild)
Expand All @@ -28,56 +21,44 @@ Documentation is at [docs/guide/README.md](https://github.com/yiisoft/yii-auth-c
[![static analysis](https://github.com/yiisoft/yii-auth-client/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/yii-auth-client/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/yii-auth-client/coverage.svg)](https://shepherd.dev/github/yiisoft/yii-auth-client)

Installation
------------

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
This extension adds [OAuth](https://oauth.net/), [OAuth2](https://oauth.net/2/) and [OpenId Connect](https://openid.net/connect/)
consumers for the [Yii framework](https://www.yiiframework.com).

```
composer require --prefer-dist yiisoft/yii-auth-client
```
## Requirements

## General usage
- PHP 7.4 or higher.

### Unit testing
## Installation

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
The package could be installed with [Composer](https://getcomposer.org):

```shell
./vendor/bin/phpunit
composer require yiisoft/yii-auth-client
```

### Mutation testing
## Documentation

The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:
- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md), [Русский](docs/guide/ru/README.md)
- [Internals](docs/internals.md)

```shell
./vendor/bin/infection
```
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).

### Static analysis
## License

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
The Yii Framework External Authentication Extension is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

```shell
./vendor/bin/psalm
```
Maintained by [Yii Software](https://www.yiiframework.com/).

### Support the project
## Support the project

[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

### Follow updates
## Follow updates

[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)

## License

The Yii Framework External Authentication Extension is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).
7 changes: 6 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Upgrading Instructions for Yii Framework external authentication via OAuth and OpenID Extension
# Yii Framework External Authentication Extension Upgrading Instructions

This file contains the upgrade notes. These notes highlight changes that could break your
application when you upgrade the package from one version to another.

## Changes summary
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"issues": "https://github.com/yiisoft/yii-auth-client/issues",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"irc": "ircs://irc.libera.chat:6697/yii",
"chat": "https://t.me/yii3en",
"source": "https://github.com/yiisoft/yii-auth-client"
},
Expand Down Expand Up @@ -93,4 +93,4 @@
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions docs/guide/pt-BR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
AuthClient Extension for Yii
============================

This extension adds [OAuth](https://oauth.net/) and [OAuth2](https://oauth.net/2/) consumers
for the Yii framework 3.0.


Getting Started
---------------

* [Installation](installation.md)
* [Quick Start](quick-start.md)

Additional topics
-----------------

* [Third Party Auth Clients](third-party-auth-clients.md)
* [Getting additional data via extra API calls](usage-api.md)
* [Creating your own auth clients](creating-your-own-auth-clients.md)
* [OAuth 2.0 direct authentication](oauth-direct-authentication.md)
* [OpenID Connect](open-id-connect.md)
* [Setup HTTP Client](setup-http-client.md)
115 changes: 115 additions & 0 deletions docs/guide/pt-BR/creating-your-own-auth-clients.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Creating your own auth clients
==============================

You may create your own auth client for any external auth provider, which supports
OpenId or OAuth protocol. To do so, first of all, you need to find out which protocol is
supported by the external auth provider, this will give you the name of the base class
for your extension:

- For OAuth 2 use [[Yiisoft\Yii\AuthClient\OAuth2]].
- For OAuth 1/1.0a use [[Yiisoft\Yii\AuthClient\OAuth1]].
- For OpenID use [[Yiisoft\Yii\AuthClient\OpenId]].

At this stage you can determine auth client default name, title and view options, declaring
corresponding methods:

```php
use Yiisoft\Yii\AuthClient\OAuth2;

class MyAuthClient extends OAuth2
{
protected function defaultName()
{
return 'my_auth_client';
}

protected function defaultTitle()
{
return 'My Auth Client';
}

protected function defaultViewOptions()
{
return [
'popupWidth' => 800,
'popupHeight' => 500,
];
}
}
```

Depending on actual base class, you will need to redeclare different fields and methods.

## [[Yiisoft\Yii\AuthClient\OAuth2]]

You will need to specify:

- Auth URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth2::authUrl|authUrl]] field.
- Token request URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth2::tokenUrl|tokenUrl]] field.
- API base URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth2::apiBaseUrl|apiBaseUrl]] field.
- User attribute fetching strategy by redeclaring [[Yiisoft\Yii\AuthClient\OAuth2::initUserAttributes()|initUserAttributes()]]
method.

For example:

```php
use Yiisoft\Yii\AuthClient\OAuth2;

class MyAuthClient extends OAuth2
{
public $authUrl = 'https://www.my.com/oauth2/auth';

public $tokenUrl = 'https://www.my.com/oauth2/token';

public $apiBaseUrl = 'https://www.my.com/apis/oauth2/v1';

protected function initUserAttributes()
{
return $this->api('userinfo', 'GET');
}
}
```

You may also specify default auth scopes.

> Note: Some OAuth providers may not follow OAuth standards clearly, introducing
differences, and may require additional efforts to implement clients for.

## [[Yiisoft\Yii\AuthClient\OAuth1]]

You will need to specify:

- Auth URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth1::authUrl|authUrl]] field.
- Request token URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth1::requestTokenUrl|requestTokenUrl]] field.
- Access token URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth1::accessTokenUrl|accessTokenUrl]] field.
- API base URL by redeclaring [[Yiisoft\Yii\AuthClient\OAuth1::apiBaseUrl|apiBaseUrl]] field.
- User attribute fetching strategy by redeclaring [[Yiisoft\Yii\AuthClient\OAuth1::initUserAttributes()|initUserAttributes()]]
method.

For example:

```php
use Yiisoft\Yii\AuthClient\OAuth1;

class MyAuthClient extends OAuth1
{
public $authUrl = 'https://www.my.com/oauth/auth';

public $requestTokenUrl = 'https://www.my.com/oauth/request_token';

public $accessTokenUrl = 'https://www.my.com/oauth/access_token';

public $apiBaseUrl = 'https://www.my.com/apis/oauth/v1';

protected function initUserAttributes()
{
return $this->api('userinfo', 'GET');
}
}
```

You may also specify default auth scopes.

> Note: Some OAuth providers may not follow OAuth standards clearly, introducing
differences, and may require additional efforts to implement clients for.

107 changes: 107 additions & 0 deletions docs/guide/pt-BR/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Installation
============

## Installing an extension

In order to install extension use Composer. Either run:

```
composer require --prefer-dist yiisoft/yii-auth-client "~3.0.0"
```

or add

```json
"yiisoft/yii-auth-client": "~3.0.0"
```

to the `require` section of your composer.json.

## Configuring application

After extension is installed you need to setup auth client collection application component:

```php
return [
'authClients' => [
'google' => [
'class' => Yiisoft\Yii\AuthClient\Client\Google::class,
'setClientId' => ['google_client_id'],
'setClientSecret' => ['google_client_secret'],
],
'facebook' => [
'class' => Yiisoft\Yii\AuthClient\Client\Facebook::class,
'setClientId' => ['facebook_client_id'],
'setClientSecret' => ['facebook_client_secret'],
],
// etc.
],
// ...
];
```

Out of the box the following clients are provided:

- [[\Yiisoft\Yii\AuthClient\Client\Facebook|Facebook]].
- [[Yiisoft\Yii\AuthClient\Client\GitHub|GitHub]].
- Google (via [[Yiisoft\Yii\AuthClient\Client\Google|OAuth]] and [[Yiisoft\Yii\AuthClient\Client\GoogleHybrid|OAuth Hybrid]]).
- [[Yiisoft\Yii\AuthClient\Client\LinkedIn|LinkedIn]].
- [[Yiisoft\Yii\AuthClient\Client\Live|Microsoft Live]].
- [[Yiisoft\Yii\AuthClient\Client\Twitter|Twitter]].
- [[Yiisoft\Yii\AuthClient\Client\VKontakte|VKontakte]].
- [[Yiisoft\Yii\AuthClient\Client\Yandex|Yandex]].

Configuration for each client is a bit different. For OAuth it's required to get client ID and secret key from
the service you're going to use. For OpenID it works out of the box in most cases.

## Storing authorization data

In order to recognize the user authenticated via external service we need to store ID provided on first authentication
and then check against it on subsequent authentications. It's not a good idea to limit login options to external
services only since these may fail and there won't be a way for the user to log in. Instead it's better to provide
both external authentication and good old login and password.

If we're storing user information in a database the corresponding migration code could be the following:

```php
class m??????_??????_auth extends \Yiisoft\Db\Migration
{
public function up()
{
$this->createTable('user', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull(),
'auth_key' => $this->string()->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->notNull(),
'email' => $this->string()->notNull(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);

$this->createTable('auth', [
'id' => $this->primaryKey(),
'user_id' => $this->integer()->notNull(),
'source' => $this->string()->notNull(),
'source_id' => $this->string()->notNull(),
]);

$this->addForeignKey('fk-auth-user_id-user-id', 'auth', 'user_id', 'user', 'id', 'CASCADE', 'CASCADE');
}

public function down()
{
$this->dropTable('auth');
$this->dropTable('user');
}
}
```

In the above example `user` is a standard table that is used in advanced project template to store user info.
Each user can authenticate using multiple external services therefore each `user` record can relate to
multiple `auth` records. In the `auth` table `source` is the name of the auth provider used and `source_id` is
unique user identifier that is provided by external service after successful login.

Using tables created above we can generate `Auth` model. No further adjustments needed.

Loading

0 comments on commit 796e66b

Please sign in to comment.