From 7bb976ec95675a97713f04c270d2ab27802805f1 Mon Sep 17 00:00:00 2001 From: warcooft Date: Fri, 13 Sep 2024 22:14:31 +0700 Subject: [PATCH 01/10] feat: add support for microsoft services --- docs/get_keys.md | 14 +++- docs/index.md | 12 +-- docs/install.md | 25 ++++-- docs/quickstart.md | 29 +++++-- src/Config/ShieldOAuthConfig.php | 7 ++ src/Language/en/ShieldOAuthLang.php | 4 + src/Language/fa/ShieldOAuthLang.php | 4 + src/Language/fr/ShieldOAuthLang.php | 4 + src/Language/id/ShieldOAuthLang.php | 4 + src/Libraries/MicrosoftOAuth.php | 126 ++++++++++++++++++++++++++++ 10 files changed, 206 insertions(+), 23 deletions(-) create mode 100644 src/Libraries/MicrosoftOAuth.php diff --git a/docs/get_keys.md b/docs/get_keys.md index 54a60ec..81da162 100644 --- a/docs/get_keys.md +++ b/docs/get_keys.md @@ -1,19 +1,22 @@ # How To Get Keys - + Obviously, receiving Keys is not directly related to `Shield OAuth`, however, to improve the documentation and convenience of our users, Therefore, we have provided helpful links on how to get keys from the three most important Google, GitHub and Yahoo. For other services, you can find the relevant steps by searching. - [How To Get Keys](#how-to-get-keys) - [Explanation About Callback](#explanation-about-callback) - [Get GitHub Keys](#get-github-keys) - [Get Google Keys](#get-google-keys) +- [Get Microsoft Keys](#get-microsoft-keys) - [Get Yahoo Keys](#get-yahoo-keys) - # Explanation About Callback + What is important in receiving the keys in each of the services is the **Callback (Redirect)** address. In this regard, you must register the address as below. + ``` https://yourBaseUrl.com/oauth/call-back ``` + `Shield OAuth` allows you to put another expression in the place of `call-back`, for this you need to make the necessary changes in the `app/Config/ShieldOAuthConfig.php` file. ```php @@ -27,10 +30,17 @@ https://yourBaseUrl.com/oauth/any-name-for-call-back ``` # Get GitHub Keys + The guide to get the `client_id` & `client_secret` keys on GitHub is [here](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app) in full. # Get Google Keys + The guide to get the `client_id` & `client_secret` keys on Google is [here](https://www.balbooa.com/gridbox-documentation/how-to-get-google-client-id-and-client-secret). +# Get Microsoft Keys + +The guide to get the `client_id` & `client_secret` keys on Microsoft is [here](https://docs.microfocus.com/doc/CS_MicrosoftOffice365_Content/1.2.3/GetClientInputs) or [here](https://learn.microsoft.com/en-us/answers/questions/834401/hi-i-want-my-client-id-and-client-secret-key). + # Get Yahoo Keys + The guide to get the `client_id` & `client_secret` keys on Yahoo is [here](https://developer.yahoo.com/apps/create/). diff --git a/docs/index.md b/docs/index.md index 9eeb1c4..4425221 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,5 @@ # Shield OAuth Documentation + [![PHPCSFixer](https://github.com/datamweb/shield-oauth/actions/workflows/phpcsfixer.yml/badge.svg)](https://github.com/datamweb/shield-oauth/actions/workflows/phpcsfixer.yml) [![PHPStan](https://github.com/datamweb/shield-oauth/actions/workflows/phpstan.yml/badge.svg)](https://github.com/datamweb/shield-oauth/actions/workflows/phpstan.yml) [![Rector](https://github.com/datamweb/shield-oauth/actions/workflows/rector.yml/badge.svg)](https://github.com/datamweb/shield-oauth/actions/workflows/rector.yml) @@ -8,16 +9,15 @@ [![Latest Stable Version](https://poser.pugx.org/datamweb/shield-oauth/v?style=for-the-badge)](https://packagist.org/packages/datamweb/shield-oauth) [![Total Downloads](https://poser.pugx.org/datamweb/shield-oauth/downloads?style=for-the-badge)](https://packagist.org/packages/datamweb/shield-oauth) [![Latest Unstable Version](https://poser.pugx.org/datamweb/shield-oauth/v/unstable?style=for-the-badge)](https://packagist.org/packages/datamweb/shield-oauth) [![License](https://poser.pugx.org/datamweb/shield-oauth/license?style=for-the-badge)](https://packagist.org/packages/datamweb/shield-oauth) [![PHP Version Require](https://poser.pugx.org/datamweb/shield-oauth/require/php?style=for-the-badge)](https://packagist.org/packages/datamweb/shield-oauth) - -`Shield OAuth` helps you to provide the possibility of login or registering users through the OAuth service. Currently, `Shield OAuth` supports `Google OAuth` and `GitHub OAuth` by default, but it allows you to implement it for any other service, including Yahoo, Facebook, Twitter, LinkedIn, GitLab and ..., this is very easy. Just create a class in route `app\Libraries\ShieldOAuth`! +`Shield OAuth` helps you to provide the possibility of login or registering users through the OAuth service. Currently, `Shield OAuth` supports `Google OAuth`, `GitHub OAuth` and `Microsoft OAuth` by default, but it allows you to implement it for any other service, including Yahoo, Facebook, Twitter, LinkedIn, GitLab and ..., this is very easy. Just create a class in route `app\Libraries\ShieldOAuth`! more info see [How to add other services](add_other_oauth.md). ## Links: -* [Installation Guide](install.md) -* [How To Get Keys](get_keys.md) -* [How to add other services](add_other_oauth.md) -* [Quick Start](quickstart.md) +- [Installation Guide](install.md) +- [How To Get Keys](get_keys.md) +- [How to add other services](add_other_oauth.md) +- [Quick Start](quickstart.md) ## Acknowledgements diff --git a/docs/install.md b/docs/install.md index 791d23a..0dc6b1c 100644 --- a/docs/install.md +++ b/docs/install.md @@ -25,15 +25,17 @@ If you have it installed as a phar, or otherwise you will need to adjust the way ```console composer require datamweb/shield-oauth:dev-develop ``` + > **Note** -> You can manually install `Shield OAuth` by extracting the project file to path `app\ThirdParty\shield-oauth` and then adding -> ->```php +> You can manually install `Shield OAuth` by extracting the project file to path `app\ThirdParty\shield-oauth` and then adding +> +> ```php > public $psr4 = [ > // add this line > 'Datamweb\ShieldOAuth' => APPPATH . 'ThirdParty/shield-oauth/src', > ]; -> ``` +> ``` +> > to the `app/Config/Autoload.php` file, however we do not recommend this. Please use the Composer. ## Add Required Columns @@ -47,6 +49,7 @@ Data of Table "users": | id | username | status | ... | first_name | last_name | avatar | +----+----------+--------+-...-+------------+-----------+--------+ ``` + Therefore, you can add `first_name`, `last_name`, and `avatar` columns to table `users` by any method you want or run the migrations: ```console @@ -57,7 +60,7 @@ php spark migrate -n Datamweb\ShieldOAuth > By default, `Shield OAuth` uses columns named `first_name`, `last_name`, and `avatar`. > For any reason, if you want to consider another name for them columns, you can do it through the config file(`config/ShieldOAuthConfig.php`) and set the desired values in: -```php +```php public array $usersColumnsName = [ 'first_name' => 'first_name', 'last_name' => 'last_name', @@ -79,7 +82,7 @@ public $globals = [ ]; ``` -## Set keys +## Set keys Receive keys `client_id` and `client_secret` from each OAuth server. To connect to any of the servers, you need to receive`client_id` and `client_secret` from them and then set them in file **.env** Or `app/Config/ShieldOAuthConfig`. @@ -112,17 +115,26 @@ public array $oauthConfigs = [ 'client_secret' => 'fsdfsdfsgdgrdg', // ... ], + 'microsoft' => [ + 'client_id' => 'example-098a-43sd-9813-9747f3gg6f6h', + 'client_secret' => 'example-qw53-446r-tyy1-856ff9ue8fdf', + // ... + ], // and other services... ``` ## Adding all login button with OAuth in View + The last step is to, You can create your own buttons in views, what is important is that the addresses should be as follows: + ```html http://localhost:8080/oauth/google http://localhost:8080/oauth/github http://localhost:8080/oauth/yahoo +http://localhost:8080/oauth/microsoft