Skip to content
Open
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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[Farsi](./README.fa-IR.md) | English
## Codeigniter Shield OAuth

## Codeigniter Shield OAuth

[![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)
[![PHPCPD](https://github.com/datamweb/shield-oauth/actions/workflows/phpcpd.yml/badge.svg)](https://github.com/datamweb/shield-oauth/actions/workflows/phpcpd.yml)


<p align="center"><img src="https://github.com/datamweb/my-repository-files/blob/main/shield-oauth/image/shieldOAuthLogo.png" alt="Logo Shield OAuth"></p>

[![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 ...
`Shield OAuth` helps you to provide the possibility of login or registering users through the OAuth service. Currently, `Shield OAuth` supports `Google OAuth`, `GitHub and `Microsoft` OAuth` by default, but it allows you to implement it for any other service, including **Yahoo**, **Facebook**, **Twitter**, **LinkedIn**, **GitLab** and ...

In `Shield OAuth`, it has been considered to be easy to use by developers and the possibility of expansion to connect to other services in the shortest possible time.

Expand All @@ -25,12 +25,15 @@ In `Shield OAuth`, it has been considered to be easy to use by developers and th
- [cURL Library](https://www.php.net/manual/en/book.curl.php) to be installed in your version of PHP

## Shield OAuth Documentation

In the documentation, I have explained how to **install**, **configure**, and how to **create custom class `NewOAuth`** connections to other services. Documentation for `Shield OAuth` can be found on the [docs](https://www.shield-oauth.codeigniter4.ir/).

## License

This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.

## Acknowledgements

Every open-source project depends on it's contributors to be a success. The following users have contributed in one manner or another in making Codeigniter `Shield OAuth`:

<a href="https://github.com/datamweb/shield-oauth/graphs/contributors">
Expand Down
16 changes: 13 additions & 3 deletions docs/get_keys.md
Original file line number Diff line number Diff line change
@@ -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.

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, Microsoft 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
Expand All @@ -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/).
12 changes: 6 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
25 changes: 19 additions & 6 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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`.
Expand Down Expand Up @@ -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
<!-- and other OAuth !>
```

However, `Shield OAuth` suggests the following for ease of use. By adding the following commands to the `vendor/codeigniter4/shield/src/Views/login.php` and `vendor/codeigniter4/shield/src/Views/register.php` file, `Shield OAuth` will automatically display all the OAuth you provide as buttons in login/register views.

```html
Expand All @@ -132,6 +144,7 @@ However, `Shield OAuth` suggests the following for ease of use. By adding the fo
```html
{{ShieldOAuthButtonForRegisterPage}}
```

Because we have used Bootstrap to make the dropdown button, you need to add the following items at the end of the views file.

```php
Expand Down
29 changes: 20 additions & 9 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

It is strongly recommended that only people who have already read the documents in full should use this section. The purpose of providing this section is to save the time of people and developers who frequently use `Shield OAuth` in different projects.

### Step 1 :
### Step 1 :

Installing the package by Composer :

```console
composer require datamweb/shield-oauth:dev-develop
```
Expand All @@ -17,24 +18,27 @@ Add `first_name`, `last_name`, and `avatar` columns to table `users` :
php spark migrate -n Datamweb\ShieldOAuth
```

### Step 3 :
### Step 3 :

- Add `{{ShieldOAuthButtonForLoginPage}}` to `vendor\codeigniter4\shield\src\Views\login.php`
- Add `{{ShieldOAuthButtonForRegisterPage}}` to `vendor\codeigniter4\shield\src\Views\register.php`
- Add

- Add `{{ShieldOAuthButtonForLoginPage}}` to `vendor\codeigniter4\shield\src\Views\login.php`
- Add `{{ShieldOAuthButtonForRegisterPage}}` to `vendor\codeigniter4\shield\src\Views\register.php`
- Add
```php
<?= $this->section('pageScripts') ?>
<script src='https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js' integrity='sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3' crossorigin='anonymous'></script>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js' integrity='sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk' crossorigin='anonymous'></script>
<?= $this->endSection() ?>
```
to `vendor\codeigniter4\shield\src\Views\login.php` and `vendor\codeigniter4\shield\src\Views\register.php`.

### Step 4 :

to `vendor\codeigniter4\shield\src\Views\login.php` and `vendor\codeigniter4\shield\src\Views\register.php`.

### Step 4 :

Receive keys `client_id` and `client_secret` from each OAuth server. and setting them in file `app\Config\ShieldOAuthConfig.php`.

callBack address is `https://yourBaseURL.com/oauth/call-back`.

```php
public array $oauthConfigs = [
'github' => [
Expand All @@ -47,6 +51,11 @@ public array $oauthConfigs = [
'client_secret' => 'fsdfsdfsgdgrdg',
// ...
],
'microsoft' => [
'client_id' => 'example-098a-43sd-9813-9747f3gg6f6h',
'client_secret' => 'example-qw53-446r-tyy1-856ff9ue8fdf',
// ...
],
// and other services...
```

Expand All @@ -57,9 +66,10 @@ public array $oauthConfigs = [
> php spark make:oauthconfig
> ```

### Step 5 :
### Step 5 :

Cancel filter for `Shield OAuth` routes.

```php
public $globals = [
'before' => [
Expand All @@ -71,4 +81,5 @@ public $globals = [
```

### Step 6 :

See `https://yourBaseURL.com/login` Or `https://yourBaseURL.com/register` Use and enjoy!
7 changes: 7 additions & 0 deletions src/Config/ShieldOAuthConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class ShieldOAuthConfig extends BaseConfig
'allow_login' => true,
'allow_register' => true,
],
'microsoft' => [
'client_id' => 'Get it from Microsoft',
'client_secret' => 'Get it from Microsoft',

'allow_login' => true,
'allow_register' => true,
],
// 'yahoo' => [
// 'client_id' => 'Get it from Yahoo',
// 'client_secret' => 'Get it from Yahoo',
Expand Down
4 changes: 4 additions & 0 deletions src/Language/en/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
'google' => 'Google',
'not_allow' => "Now you can't login or register with Google!",
],
'Microsoft' => [
'microsoft' => 'Microsoft',
'not_allow' => "Now you can't login or register with Microsoft!",
],
// 'Yahoo' => [
// 'yahoo' => 'Yahoo',
// 'not_allow' => "Now you can't login or register with Yahoo!",
Expand Down
4 changes: 4 additions & 0 deletions src/Language/fa/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
'google' => 'گوگل',
'not_allow' => 'اکنون امکان ورود و یا ثبت نام با گوگل وجود ندارد.',
],
'Microsoft' => [
'microsoft' => 'Microsoft',
'not_allow' => "(To be translated) Now you can't login or register with Microsoft!",
],
// 'Yahoo' => [
// 'yahoo' => 'یاهو',
// 'not_allow' => "اکنون امکان ورود و یا ثبت نام با یاهو وجود ندارد!",
Expand Down
4 changes: 4 additions & 0 deletions src/Language/fr/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
'google' => 'Google',
'not_allow' => 'Vous ne pouvez pas vous connecter ou vous inscrire avec Google maintenant!',
],
'Microsoft' => [
'microsoft' => 'Microsoft',
'not_allow' => 'Vous ne pouvez pas vous connecter ou vous inscrire avec Microsoft maintenant!',
],
// 'Yahoo' => [
// 'yahoo' => 'Yahoo',
// 'not_allow' => "Vous ne pouvez pas vous connecter ou vous inscrire avec Yahoo maintenant!",
Expand Down
4 changes: 4 additions & 0 deletions src/Language/id/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
'google' => 'Google',
'not_allow' => 'Sekarang Anda tidak bisa masuk atau mendaftar dengan Google!',
],
'Microsoft' => [
'microsoft' => 'Microsoft',
'not_allow' => 'Sekarang Anda tidak bisa masuk atau mendaftar dengan Microsoft!',
],
// 'Yahoo' => [
// 'yahoo' => 'Yahoo',
// 'not_allow' => 'Sekarang Anda tidak bisa masuk atau mendaftar dengan Yahoo!',
Expand Down
5 changes: 3 additions & 2 deletions src/Libraries/Basic/ShieldOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function otherOAuth()
{
$pieces = explode('|', $this->allOAuth());

return array_diff($pieces, ['github', 'google']);
return array_diff($pieces, ['github', 'google', 'microsoft']);
}

/**
Expand Down Expand Up @@ -127,10 +127,11 @@ public function makeOAuthButton(string $forPage = 'login'): string

$Button .= '<a href=' . base_url('oauth/google') . " class='btn btn-outline-secondary' aria-current='page'>" . lang('ShieldOAuthLang.Google.google') . '</a>';
$Button .= '<a href=' . base_url('oauth/github') . " class='btn btn-outline-secondary' aria-current='page'>" . lang('ShieldOAuthLang.Github.github') . '</a>';
$Button .= '<a href=' . base_url('oauth/microsoft') . " class='btn btn-outline-secondary' aria-current='page'>" . lang('ShieldOAuthLang.Microsoft.microsoft') . '</a>';
if ($this->otherOAuth() !== []) {
$Button .= "<div class='btn-group' role='group'>
<button type='button' class='btn btn-outline-secondary dropdown-toggle' data-bs-toggle='dropdown' aria-expanded='false'>"
. lang('ShieldOAuthLang.other') . "
. lang('ShieldOAuthLang.other') . "
</button>
<ul class='dropdown-menu'>";

Expand Down
Loading
Loading