├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── config.yml
│ ├── feature_request.md
│ └── planned-work.md
├── dependabot.yml
└── workflows
│ ├── docs.yml
│ ├── no-merge-commits.yml
│ ├── phpcpd.yml
│ ├── phpcsfixer.yml
│ ├── phpstan.yml
│ └── rector.yml
├── .gitignore
├── .php-cs-fixer.dist.php
├── LICENSE
├── README.md
├── admin
├── pre-commit
└── setup.sh
├── composer.json
├── docs
├── CNAME
├── add_other_oauth.md
├── get_keys.md
├── index.md
├── install.md
└── quickstart.md
├── mkdocs.yml
├── phpstan-baseline.php
├── phpstan.neon.dist
├── rector.php
└── src
├── Commands
├── Generators
│ ├── NewShieldOauthGenerator.php
│ └── Views
│ │ └── newoauth.tpl.php
└── OAuthSetup.php
├── Config
├── Registrar.php
├── Routes.php
├── Services.php
└── ShieldOAuthConfig.php
├── Controllers
└── OAuthController.php
├── Database
└── Migrations
│ └── 2022-10-20-182737_ShieldOAuth.php
├── Language
├── en
│ └── ShieldOAuthLang.php
├── fa
│ └── ShieldOAuthLang.php
├── fr
│ └── ShieldOAuthLang.php
├── id
│ └── ShieldOAuthLang.php
└── pt-BR
│ └── ShieldOAuthLang.php
├── Libraries
├── Basic
│ ├── AbstractOAuth.php
│ ├── ControllersInterface.php
│ └── ShieldOAuth.php
├── GithubOAuth.php
└── GoogleOAuth.php
├── Models
└── ShieldOAuthModel.php
└── Views
└── Decorators
└── ShieldOAuth.php
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | name: Bug report
2 | description: Create a report to help us improve Shield OAuth
3 | title: "Bug: "
4 | labels: ['bug']
5 |
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | Thanks for taking the time to fill out this bug report!
11 |
12 | Before you begin, **please ensure that there are no existing issues,
13 | whether still open or closed, related to your report**.
14 | If there is, your report will be closed promptly.
15 |
16 | ---
17 |
18 | - type: input
19 | id: php-version
20 | attributes:
21 | label: PHP Version
22 | description: |
23 | e.g. 8.1.11
24 | validations:
25 | required: true
26 |
27 | - type: input
28 | id: codeigniter-version
29 | attributes:
30 | label: CodeIgniter4 Version
31 | description: |
32 | e.g. 4.2.8
33 | validations:
34 | required: true
35 |
36 | - type: input
37 | id: shield-version
38 | attributes:
39 | label: Shield Version
40 | description: |
41 | e.g. 1.0.0-beta.3
42 | If you are not using the [latest version](https://github.com/codeigniter4/shield/releases), please
43 | check to see if the problem occurs with the latest version.
44 | validations:
45 | required: true
46 |
47 | - type: dropdown
48 | id: shield-oauth-version
49 | attributes:
50 | label: Shield OAuth Version?
51 | description: |
52 | e.g. 1.0.0-beta
53 | If you are not using the [latest version](https://github.com/datamweb/shield-oauth/releases), please
54 | check to see if the problem occurs with the latest version.
55 | multiple: true
56 | options:
57 | - dev-develop
58 | - dev-main
59 | validations:
60 | required: true
61 |
62 | - type: dropdown
63 | id: operating-systems
64 | attributes:
65 | label: Which operating systems have you tested for this bug?
66 | description: You may select more than one.
67 | multiple: true
68 | options:
69 | - macOS
70 | - Windows
71 | - Linux
72 | validations:
73 | required: true
74 |
75 | - type: dropdown
76 | id: server
77 | attributes:
78 | label: Which server did you use?
79 | options:
80 | - apache
81 | - cli
82 | - cli-server (PHP built-in webserver)
83 | - cgi-fcgi
84 | - fpm-fcgi
85 | - phpdbg
86 | validations:
87 | required: true
88 |
89 | - type: input
90 | id: database
91 | attributes:
92 | label: Database
93 | description: e.g. MySQL 5.6, MariaDB 10.2, PostgreSQL 9.6
94 | validations:
95 | required: true
96 |
97 | - type: textarea
98 | id: add-customization-oauth
99 | attributes:
100 | label: Did you add customize OAuth?
101 | description: |
102 | If "YES", please tell for which site(yahoo,tiwtter and ...) you added and how?
103 | If "No," please indicate "No."
104 | validations:
105 | required: true
106 |
107 | - type: textarea
108 | id: description
109 | attributes:
110 | label: What happened?
111 | placeholder: Tell us what you see!
112 | validations:
113 | required: true
114 |
115 | - type: textarea
116 | attributes:
117 | label: Steps to Reproduce
118 | description: Steps to reproduce the behavior.
119 | validations:
120 | required: true
121 |
122 | - type: textarea
123 | attributes:
124 | label: Expected Output
125 | description: What do you expect to happen instead of this filed bug?
126 | validations:
127 | required: true
128 |
129 | - type: textarea
130 | attributes:
131 | label: Anything else?
132 | description: |
133 | Links? References? Anything that will give us more context about the issue you are encountering!
134 |
135 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
136 | validations:
137 | required: false
138 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: GitHub Discussions
4 | url: https://github.com/datamweb/shield-oauth/discussions
5 | about: Please ask your support questions in the Discussions. Thanks!
6 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: How to submit a feature request
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | Please submit feature requests to [Discussions](https://github.com/datamweb/shield-oauth/discussions/categories/ideas).
11 | We use GitHub Issues to track bugs and planned work.
12 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/planned-work.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Planned work
3 | about: Approved work planning
4 | title: 'Dev: '
5 | labels: dev
6 | assignees: ''
7 |
8 | ---
9 |
10 | Repo maintainers will create "issues" for planned work, so it can be tracked.
11 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: composer
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "08:30"
8 | timezone: "Asia/Tehran"
9 | open-pull-requests-limit: 5
10 | target-branch: "develop"
11 | reviewers:
12 | - "datamweb"
13 | assignees:
14 | - "datamweb"
15 | labels:
16 | - "dependa bot"
17 |
18 | - package-ecosystem: "github-actions"
19 | directory: "/"
20 | schedule:
21 | interval: daily
22 | time: "08:30"
23 | timezone: "Asia/Tehran"
24 | open-pull-requests-limit: 5
25 | target-branch: "develop"
26 | reviewers:
27 | - "datamweb"
28 | assignees:
29 | - "datamweb"
30 | labels:
31 | - "dependa bot"
32 |
33 |
--------------------------------------------------------------------------------
/.github/workflows/docs.yml:
--------------------------------------------------------------------------------
1 | name: docs
2 | on:
3 | push:
4 | branches:
5 | - develop
6 | - main
7 | permissions:
8 | contents: write
9 | jobs:
10 | deploy:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout Repository
14 | uses: actions/checkout@v4
15 | with:
16 | fetch-depth: 0
17 | - name: Setup Python
18 | uses: actions/setup-python@v5
19 | with:
20 | python-version: 3.x
21 | - name: Install Dependencies
22 | run: |
23 | pip3 install mkdocs-material
24 | pip3 install mkdocs-git-revision-date-localized-plugin
25 | - name: Publish Documentation
26 | run: mkdocs gh-deploy --force
27 |
--------------------------------------------------------------------------------
/.github/workflows/no-merge-commits.yml:
--------------------------------------------------------------------------------
1 | name: Detect Merge Commits
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - develop
7 | - main
8 |
9 | permissions:
10 | contents: read
11 | pull-requests: read
12 |
13 | jobs:
14 | test:
15 | name: Check for merge commits
16 | runs-on: ubuntu-22.04
17 |
18 | steps:
19 | - name: Checkout
20 | uses: actions/checkout@v4
21 |
22 | - name: Run test
23 | uses: NexusPHP/no-merge-commits@v2.2.1
24 | with:
25 | token: ${{ secrets.GITHUB_TOKEN }}
26 |
--------------------------------------------------------------------------------
/.github/workflows/phpcpd.yml:
--------------------------------------------------------------------------------
1 | name: PHPCPD
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - develop
7 | paths:
8 | - '**.php'
9 | - '.github/workflows/phpcpd.yml'
10 | push:
11 | branches:
12 | - develop
13 | paths:
14 | - '**.php'
15 | - '.github/workflows/phpcpd.yml'
16 |
17 | jobs:
18 | build:
19 | name: Code Copy-Paste Detection
20 | runs-on: ubuntu-latest
21 | if: "!contains(github.event.head_commit.message, '[ci skip]')"
22 |
23 | steps:
24 | - name: Checkout
25 | uses: actions/checkout@v4
26 |
27 | - name: Setup PHP
28 | uses: shivammathur/setup-php@v2
29 | with:
30 | php-version: '8.0'
31 | tools: phpcpd
32 | extensions: dom, mbstring
33 | coverage: none
34 |
35 | - name: Detect duplicate code
36 | run: phpcpd src/ --min-lines 35 --exclude src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php
--------------------------------------------------------------------------------
/.github/workflows/phpcsfixer.yml:
--------------------------------------------------------------------------------
1 | name: PHPCSFixer
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - develop
7 | paths:
8 | - '**.php'
9 | - '.github/workflows/phpcsfixer.yml'
10 | push:
11 | branches:
12 | - develop
13 | paths:
14 | - '**.php'
15 | - '.github/workflows/phpcsfixer.yml'
16 |
17 | jobs:
18 | build:
19 | name: PHP ${{ matrix.php-versions }} Coding Standards
20 | runs-on: ubuntu-latest
21 | if: "!contains(github.event.head_commit.message, '[ci skip]')"
22 | strategy:
23 | fail-fast: false
24 | matrix:
25 | php-versions: ['7.4', '8.0', '8.1']
26 |
27 | steps:
28 | - name: Checkout
29 | uses: actions/checkout@v4
30 |
31 | - name: Set up PHP
32 | uses: shivammathur/setup-php@v2
33 | with:
34 | php-version: ${{ matrix.php-versions }}
35 | extensions: json, tokenizer
36 | coverage: none
37 | env:
38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 |
40 | - name: Get composer cache directory
41 | id: composer-cache
42 | run: echo "::set-output name=dir::$(composer config cache-files-dir)"
43 |
44 | - name: Cache composer dependencies
45 | uses: actions/cache@v4
46 | with:
47 | path: ${{ steps.composer-cache.outputs.dir }}
48 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
49 | restore-keys: ${{ runner.os }}-composer-
50 |
51 | - name: Install dependencies
52 | run: |
53 | if [ -f composer.lock ]; then
54 | composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
55 | else
56 | composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
57 | fi
58 |
59 | - name: Check code for standards compliance
60 | run: vendor/bin/php-cs-fixer fix --verbose --ansi --dry-run --using-cache=no --diff
61 |
--------------------------------------------------------------------------------
/.github/workflows/phpstan.yml:
--------------------------------------------------------------------------------
1 | name: PHPStan
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - develop
7 | paths:
8 | - '**.php'
9 | - 'composer.*'
10 | - 'phpstan*'
11 | - '.github/workflows/phpstan.yml'
12 | push:
13 | branches:
14 | - develop
15 | paths:
16 | - '**.php'
17 | - 'composer.*'
18 | - 'phpstan*'
19 | - '.github/workflows/phpstan.yml'
20 |
21 | jobs:
22 | build:
23 | name: PHP ${{ matrix.php-versions }} Static Analysis
24 | runs-on: ubuntu-latest
25 | if: "!contains(github.event.head_commit.message, '[ci skip]')"
26 | strategy:
27 | fail-fast: false
28 | matrix:
29 | php-versions: ['7.4', '8.0', '8.1']
30 |
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v4
34 |
35 | - name: Setup PHP
36 | uses: shivammathur/setup-php@v2
37 | with:
38 | php-version: ${{ matrix.php-versions }}
39 | tools: phpstan, phpunit
40 | extensions: intl, json, mbstring, xml
41 | coverage: none
42 | env:
43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44 |
45 | - name: Get composer cache directory
46 | run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
47 |
48 | - name: Cache composer dependencies
49 | uses: actions/cache@v4
50 | with:
51 | path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
52 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
53 | restore-keys: ${{ runner.os }}-composer-
54 |
55 | - name: Create PHPStan cache directory
56 | run: mkdir -p build/phpstan
57 |
58 | - name: Cache PHPStan results
59 | uses: actions/cache@v4
60 | with:
61 | path: build/phpstan
62 | key: ${{ runner.os }}-phpstan-${{ github.sha }}
63 | restore-keys: ${{ runner.os }}-phpstan-
64 |
65 | - name: Install dependencies
66 | run: |
67 | if [ -f composer.lock ]; then
68 | composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
69 | else
70 | composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
71 | fi
72 |
73 | - name: Run static analysis
74 | run: vendor/bin/phpstan analyze
75 |
--------------------------------------------------------------------------------
/.github/workflows/rector.yml:
--------------------------------------------------------------------------------
1 | name: Rector
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - develop
7 | paths:
8 | - '**.php'
9 | - 'composer.*'
10 | - 'rector.php'
11 | - '.github/workflows/rector.yml'
12 | push:
13 | branches:
14 | - develop
15 | paths:
16 | - '**.php'
17 | - 'composer.*'
18 | - 'rector.php'
19 | - '.github/workflows/rector.yml'
20 |
21 | jobs:
22 | build:
23 | name: PHP ${{ matrix.php-versions }} Rector Analysis
24 | runs-on: ubuntu-latest
25 | if: "!contains(github.event.head_commit.message, '[ci skip]')"
26 | strategy:
27 | fail-fast: false
28 | matrix:
29 | php-versions: ['7.4', '8.0', '8.1']
30 |
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v4
34 |
35 | - name: Set up PHP
36 | uses: shivammathur/setup-php@v2
37 | with:
38 | php-version: ${{ matrix.php-versions }}
39 | tools: phpstan
40 | extensions: intl, json, mbstring, xml
41 | coverage: none
42 | env:
43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44 |
45 | - name: Get composer cache directory
46 | run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
47 |
48 | - name: Cache composer dependencies
49 | uses: actions/cache@v4
50 | with:
51 | path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
52 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
53 | restore-keys: ${{ runner.os }}-composer-
54 |
55 | - name: Install dependencies
56 | run: |
57 | if [ -f composer.lock ]; then
58 | composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
59 | else
60 | composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
61 | fi
62 |
63 | - name: Analyze for refactoring
64 | run: |
65 | composer global require --dev rector/rector:^1.0.0
66 | rector process --dry-run --no-progress-bar
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | build/
3 | phpunit*.xml
4 | phpunit
5 | *.cache
6 | composer.lock
7 | .DS_Store
8 | .idea/
9 | site/
--------------------------------------------------------------------------------
/.php-cs-fixer.dist.php:
--------------------------------------------------------------------------------
1 |
9 | *
10 | * For the full copyright and license information, please view
11 | * the LICENSE file that was distributed with this source code.
12 | */
13 |
14 | use CodeIgniter\CodingStandard\CodeIgniter4;
15 | use Nexus\CsConfig\Factory;
16 | use PhpCsFixer\Finder;
17 |
18 | $finder = Finder::create()
19 | ->files()
20 | ->in([
21 | __DIR__ . '/src/',
22 | // __DIR__ . '/tests/',
23 | ])
24 | ->exclude('build')
25 | ->append([
26 | __FILE__,
27 | __DIR__ . '/rector.php',
28 | ]);
29 |
30 | $overrides = [
31 | 'declare_strict_types' => true,
32 | 'void_return' => true,
33 | 'modernize_strpos' => false,
34 | ];
35 |
36 | $options = [
37 | 'finder' => $finder,
38 | 'cacheFile' => '.php-cs-fixer.cache',
39 | ];
40 |
41 | return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary(
42 | 'Shield OAuth',
43 | 'Datamweb',
44 | 'pooya_parsa_dadashi@yahoo.com'
45 | );
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022-2023 Pooya Parsa Dadashi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [Farsi](./README.fa-IR.md) | English
2 | ## Codeigniter Shield OAuth
3 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpcsfixer.yml)
4 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpstan.yml)
5 | [](https://github.com/datamweb/shield-oauth/actions/workflows/rector.yml)
6 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpcpd.yml)
7 |
8 |
9 |

10 |
11 | [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth)
12 |
13 |
14 | `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 ...
15 |
16 | 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.
17 |
18 | 
19 |
20 | ## Requirements
21 |
22 | - [Composer](https://getcomposer.org)
23 | - [Codeigniter](https://codeigniter4.github.io/CodeIgniter4/installation/installing_composer.html#installation) **v4.3.5** or later
24 | - [Codeigniter Shield](https://github.com/codeigniter4/shield)
25 | - [cURL Library](https://www.php.net/manual/en/book.curl.php) to be installed in your version of PHP
26 |
27 | ## Shield OAuth Documentation
28 | 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/).
29 |
30 | ## License
31 | This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.
32 |
33 | ## Acknowledgements
34 | 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`:
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/admin/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if [ "$FILES" != "" ]; then
3 | echo "Running PHP CS Fixer..."
4 |
5 | if [ -d /proc/cygdrive ]; then
6 | ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
7 | else
8 | php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
9 | fi
10 |
11 | if [ $? != 0 ]; then
12 | echo "Some files are not following the coding standards. Please fix them before commit (try 'composer style')."
13 | exit 1
14 | fi
15 | fi
16 |
17 | exit $?
18 |
--------------------------------------------------------------------------------
/admin/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Install a pre-commit hook that
4 | # automatically runs phpcs to fix styles
5 | cp admin/pre-commit .git/hooks/pre-commit
6 | chmod +x .git/hooks/pre-commit
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "datamweb/shield-oauth",
3 | "description": "OAuth for CodeIgniter Shield",
4 | "license": "MIT",
5 | "type": "library",
6 | "keywords": [
7 | "codeigniter4",
8 | "shield",
9 | "oauth",
10 | "googleOauth",
11 | "githubOauth",
12 | "authentication",
13 | "authorization"
14 | ],
15 | "authors": [
16 | {
17 | "name": "Pooya Parsa Dadashi",
18 | "email": "pooya_parsa_dadashi@yahoo.com",
19 | "role": "Developer"
20 | }
21 | ],
22 | "homepage": "https://github.com/datamweb/shield-oauth",
23 | "minimum-stability": "dev",
24 | "prefer-stable": true,
25 | "require": {
26 | "php": "^7.4.3 || ^8.0 || ^8.1 || ^8.2",
27 | "ext-curl": "*",
28 | "codeigniter4/shield": "^1.0"
29 | },
30 | "require-dev": {
31 | "codeigniter4/devkit": "^1.0",
32 | "codeigniter4/framework": "^4.3.5",
33 | "codeigniter4/shield": "^1.0",
34 | "rector/rector": "1.2.10"
35 | },
36 | "autoload": {
37 | "psr-4": {
38 | "Datamweb\\ShieldOAuth\\": "src"
39 | },
40 | "exclude-from-classmap": [
41 | "**/Database/Migrations/**"
42 | ]
43 | },
44 | "autoload-dev": {
45 | "psr-4": {
46 | "Tests\\": "tests",
47 | "Tests\\Support\\": "tests/_support"
48 | }
49 | },
50 | "scripts": {
51 | "post-update-cmd": [
52 | "bash admin/setup.sh"
53 | ],
54 | "ci": [
55 | "Composer\\Config::disableProcessTimeout",
56 | "@cs"
57 | ],
58 | "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff",
59 | "cs-fix": "php-cs-fixer fix --ansi --verbose --diff",
60 | "style": "@cs-fix"
61 | },
62 | "config": {
63 | "allow-plugins": {
64 | "phpstan/extension-installer": true
65 | }
66 | },
67 | "support": {
68 | "forum": "https://github.com/datamweb/shield-oauth/discussions",
69 | "source": "https://github.com/datamweb/shield-oauth",
70 | "issues": "https://github.com/datamweb/shield-oauth/issues",
71 | "docs": "https://www.shield-oauth.codeigniter4.ir"
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/docs/CNAME:
--------------------------------------------------------------------------------
1 | www.shield-oauth.codeigniter4.ir
2 |
--------------------------------------------------------------------------------
/docs/add_other_oauth.md:
--------------------------------------------------------------------------------
1 | # Adding New OAuth To Shield OAuth
2 |
3 | Shield OAuth supports *Google OAuth* and *GitHub OAuth* out-of-the-box and also provides an easy way to connect any server that offers **OAuth** to it. This guide explains how to achieve this.
4 |
5 | - [Adding New OAuth To Shield OAuth](#adding-new-oauth-to-shield-oauth)
6 | - [Setup Instruction](#setup-instruction)
7 | - [Command Setup](#command-setup)
8 | - [Manual Setup](#manual-setup)
9 | - [Available Methods](#available-methods)
10 | - [YahooOAuth Example Class](#yahoooauth-example-class)
11 |
12 | ## Setup Instruction
13 |
14 | ### Command Setup
15 |
16 | 1. Run the following command. This command handles steps 1 - 3 of *Manual Setup*.
17 |
18 | ```console
19 | php spark make:oauth Example
20 | ```
21 |
22 | > **Note** The name of the new OAuth you want to create doesn't need to contain the `OAuth` suffix. The command will automatically add it to the class name for you.
23 |
24 | This command will automatically generate new files *ExampleOAuth.php*, *ShieldOAuthLang.php* in the **app/Libraries/ShieldOAuth**, **app/Language/en** paths respectively and also update the *ShieldOAuthConfig.php* file in the **app/Config** path.
25 |
26 | > **Note** The *ShieldOAuthConfig.php* file must be present in your **app/Config** path for this command to run successfully. So ensure that you have run the `make:oauthconfig` command first, as stated [here](install.md#set-keys).
27 |
28 | 2. Configure the files.
29 |
30 | ```php
31 | // updated file - app/Config/ShieldOAuthConfig.php
32 | [
36 | 'client_id' => 'Get this from the OAuth server',
37 | 'client_secret' => 'Get this from the OAuth server',
38 |
39 | 'allow_login' => true,
40 | 'allow_register' => true,
41 | ],
42 | ];
43 |
44 | ```
45 |
46 | ```php
47 | // new file - app/Libraries/ShieldOAuth/ExampleOAuth.php
48 | See [YahooOAuth](#yahoooauth-example-class) example for full code.
99 |
100 | ### Manual Setup
101 |
102 | 1. Create a file *ExampleOAuth* in the **app/Libraries/ShieldOAuth** path with the following contents. The **OAuth** suffix is mandatory in creating each new class. For example, if you want to add Yahoo, you should create a file named **YahooOAuth**.
103 |
104 | ```php
105 | See [YahooOAuth](#yahoooauth-example-class) example for full code.
156 |
157 | 2. **Config Setup** Add the new OAuth config keys to the **app/Config/ShieldOAuthConfig.php** file.
158 |
159 | ```php
160 | [
164 | 'client_id' => 'Get this from the OAuth server',
165 | 'client_secret' => 'Get this from the OAuth server',
166 |
167 | 'allow_login' => true,
168 | 'allow_register' => true,
169 | ],
170 | //...
171 | ];
172 |
173 | ```
174 |
175 | 3. **Language setup** Add the following values to the **app/Language/en/ShieldOAuthLang.php** file. Create the file if it doesn't exist.
176 |
177 | ```php
178 | return [
179 | // ...
180 | 'Example' => [
181 | 'not_allow' => 'Now you can\'t login or register with Example!',
182 | 'example' => 'Example',
183 | ],
184 | // ...
185 | ];
186 | ```
187 |
188 | 4. **Translations** Depending on the requirements of your application, you can translate the language file using the same keys, in as many languages as possible. See [CodeIgniter docs](https://codeigniter.com/user_guide/outgoing/localization.html#creating-language-files) for more information. Also note that the file name for each language must be **ShieldOAuthLang.php**.
189 |
190 | ## Available Methods
191 |
192 | Your new *OAuth* file/class has just one requirement. It must extend `Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth`. The abstract class `AbstractOAuth` implement methods `makeGoLink($state)`, `fetchAccessTokenWithAuthCode($allGet)`, `fetchUserInfoWithToken()` and `setColumnsName(string $nameOfProcess, $userInfo)`, which should be built according to the documentation of each server.
193 |
194 | The `AbstractOAuth` defines four methods for your usage:
195 |
196 | 1. `makeGoLink($state)` In this method, you need to create a link to transfer the user to the new provider. The output of this method is a `string` in the form of URL. For example, regarding Yahoo, you can follow the instructions available [here](https://developer.yahoo.com/oauth2/guide/flows_authcode/#step-2-get-an-authorization-url-and-authorize-access) to create this link.
197 | 2. `fetchAccessTokenWithAuthCode($allGet)` In this method, you should try to get the value of `access_token` according to the code received from the previous method. The output of this method is of `void`. For Yahoo, you can see the description [here](https://developer.yahoo.com/oauth2/guide/flows_authcode/#step-4-exchange-authorization-code-for-access-token). Everything is ready, just replace.
198 | 3. `fetchUserInfoWithToken()` In this method, you try to receive user information (including first name, last name, email, etc) according to the token code set in the previous step.The output of this method is a `object` of user info(email, name, ...). See [here](https://developer.yahoo.com/oauth2/guide/OpenID2) for more details about Yahoo.
199 | 4. `setColumnsName(string $nameOfProcess, $userInfo)` In this method, you set the fields received from each service OAuth to be recorded in each column of the table.
200 |
201 | ## YahooOAuth Example Class
202 |
203 | ```php
204 | token = $token;
234 | $this->client = Services::curlrequest();
235 |
236 | $this->config = config('ShieldOAuthConfig');
237 | $this->callback_url = base_url('oauth/' . $this->config->call_back_route);
238 | $this->client_id = env('ShieldOAuthConfig.yahoo.client_id', $this->config->oauthConfigs['yahoo']['client_id']);
239 | $this->client_secret = env('ShieldOAuthConfig.yahoo.client_secret', $this->config->oauthConfigs['yahoo']['client_secret']);
240 | }
241 |
242 | public function makeGoLink(string $state): string
243 | {
244 | $yahooURL= self::$API_CODE_URL."?response_type=code&client_id={$this->client_id}&redirect_uri={$this->callback_url}&state={$state}";
245 |
246 | return $yahooURL;
247 | }
248 |
249 | public function fetchAccessTokenWithAuthCode(array $allGet): void
250 | {
251 |
252 | $client = \Config\Services::curlrequest();
253 | try {
254 | //send request to API URL
255 | $response = $client->request('POST', self::$API_TOKEN_URL, [
256 | 'form_params' => [
257 | 'client_id' => $this->client_id ,
258 | 'client_secret' => $this->client_secret ,
259 | 'redirect_uri' => $this->callback_url,
260 | 'code' => $allGet['code'],
261 | 'grant_type' => 'authorization_code'
262 | ],
263 | 'http_errors' => false,
264 | ]);
265 |
266 | } catch (Exception $e) {
267 | die($e->getMessage());
268 | }
269 |
270 | $token = json_decode($response->getBody())->access_token;
271 | $this->setToken($token);
272 | }
273 |
274 | protected function fetchUserInfoWithToken(): object
275 | {
276 | // send request to API URL
277 | try {
278 | $response = $this->client->request('GET', self::$API_USER_INFO_URL, [
279 | 'headers' => [
280 | 'Authorization' => 'Bearer ' . $this->getToken(),
281 | ],
282 | 'http_errors' => false,
283 | ]);
284 | } catch (Exception $e) {
285 | die($e->getMessage());
286 | }
287 |
288 | return json_decode($response->getBody());
289 | }
290 |
291 | protected function setColumnsName(string $nameOfProcess, object $userInfo): array
292 | {
293 | if($nameOfProcess === 'syncingUserInfo'){
294 | $usersColumnsName = [
295 | $this->config->usersColumnsName['first_name'] => $userInfo->given_name,
296 | $this->config->usersColumnsName['last_name'] => $userInfo->family_name,
297 | $this->config->usersColumnsName['avatar'] => $userInfo->picture,
298 | ];
299 | }
300 |
301 | if($nameOfProcess === 'newUser'){
302 | $usersColumnsName = [
303 | 'username' => $userInfo->nickname,
304 | 'email' => $userInfo->email,
305 | 'password' => random_string('crypto', 32),
306 | 'active' => $userInfo->email_verified,
307 | $this->config->usersColumnsName['first_name'] => $userInfo->given_name,
308 | $this->config->usersColumnsName['last_name'] => $userInfo->family_name,
309 | $this->config->usersColumnsName['avatar'] => $userInfo->picture,
310 | ];
311 | }
312 |
313 | return $usersColumnsName;
314 | }
315 | }
316 | ```
317 |
--------------------------------------------------------------------------------
/docs/get_keys.md:
--------------------------------------------------------------------------------
1 | # How To Get Keys
2 |
3 | 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.
4 |
5 | - [How To Get Keys](#how-to-get-keys)
6 | - [Explanation About Callback](#explanation-about-callback)
7 | - [Get GitHub Keys](#get-github-keys)
8 | - [Get Google Keys](#get-google-keys)
9 | - [Get Yahoo Keys](#get-yahoo-keys)
10 |
11 |
12 | # Explanation About Callback
13 | 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.
14 | ```
15 | https://yourBaseUrl.com/oauth/call-back
16 | ```
17 | `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.
18 |
19 | ```php
20 | public string $call_back_route = 'any-name-for-call-back';
21 | ```
22 |
23 | Be careful that you must provide the same address for all services.
24 |
25 | ```
26 | https://yourBaseUrl.com/oauth/any-name-for-call-back
27 | ```
28 |
29 | # Get GitHub Keys
30 | 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.
31 |
32 | # Get Google Keys
33 | 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).
34 |
35 | # Get Yahoo Keys
36 | The guide to get the `client_id` & `client_secret` keys on Yahoo is [here](https://developer.yahoo.com/apps/create/).
37 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | # Shield OAuth Documentation
2 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpcsfixer.yml)
3 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpstan.yml)
4 | [](https://github.com/datamweb/shield-oauth/actions/workflows/rector.yml)
5 | [](https://github.com/datamweb/shield-oauth/actions/workflows/phpcpd.yml)
6 |
7 | 
8 |
9 | [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth) [](https://packagist.org/packages/datamweb/shield-oauth)
10 |
11 |
12 | `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`!
13 | more info see [How to add other services](add_other_oauth.md).
14 |
15 | ## Links:
16 |
17 | * [Installation Guide](install.md)
18 | * [How To Get Keys](get_keys.md)
19 | * [How to add other services](add_other_oauth.md)
20 | * [Quick Start](quickstart.md)
21 |
22 | ## Acknowledgements
23 |
24 | Every open-source project depends on it's contributors to be a success. The following users have
25 | contributed in one manner or another in making `Shield OAuth`:
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/docs/install.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | - [Installation](#installation)
4 | - [Requirements](#requirements)
5 | - [Composer Installation](#composer-installation)
6 | - [Add Required Columns](#add-required-columns)
7 | - [Cancel Filter For Shield OAuth Routes](#cancel-filter-for-shield-oauth-routes)
8 | - [Set keys](#set-keys)
9 | - [Adding all login button with OAuth in View](#adding-all-login-button-with-oauth-in-view)
10 |
11 | These instructions assume that you have already installed the **CodeIgniter 4 app starter** and **Shield** as the basis for your new project, set up your `.env` file, and created a database that you can access via the Spark CLI script.
12 |
13 | ## Requirements
14 |
15 | - [Composer](https://getcomposer.org)
16 | - [Codeigniter](https://codeigniter4.github.io/CodeIgniter4/installation/installing_composer.html#installation) **v4.3.5** or later
17 | - [Codeigniter Shield](https://github.com/codeigniter4/shield)
18 | - [cURL Library](https://www.php.net/manual/en/book.curl.php) to be installed in your version of PHP
19 |
20 | ## Composer Installation
21 |
22 | Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
23 | If you have it installed as a phar, or otherwise you will need to adjust the way you call composer itself.
24 |
25 | ```console
26 | composer require datamweb/shield-oauth:dev-develop
27 | ```
28 | > **Note**
29 | > You can manually install `Shield OAuth` by extracting the project file to path `app\ThirdParty\shield-oauth` and then adding
30 | >
31 | >```php
32 | > public $psr4 = [
33 | > // add this line
34 | > 'Datamweb\ShieldOAuth' => APPPATH . 'ThirdParty/shield-oauth/src',
35 | > ];
36 | > ```
37 | > to the `app/Config/Autoload.php` file, however we do not recommend this. Please use the Composer.
38 |
39 | ## Add Required Columns
40 |
41 | `Shield OAuth` needs to make some changes in Shield `users` Table. In general, you should have the following items in `users` Table.
42 |
43 | ```console
44 | Data of Table "users":
45 |
46 | +----+----------+--------+-...-+------------+-----------+--------+
47 | | id | username | status | ... | first_name | last_name | avatar |
48 | +----+----------+--------+-...-+------------+-----------+--------+
49 | ```
50 | Therefore, you can add `first_name`, `last_name`, and `avatar` columns to table `users` by any method you want or run the migrations:
51 |
52 | ```console
53 | php spark migrate -n Datamweb\ShieldOAuth
54 | ```
55 |
56 | > **Note**
57 | > By default, `Shield OAuth` uses columns named `first_name`, `last_name`, and `avatar`.
58 | > 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:
59 |
60 | ```php
61 | public array $usersColumnsName = [
62 | 'first_name' => 'first_name',
63 | 'last_name' => 'last_name',
64 | 'avatar' => 'avatar',
65 | ];
66 | ```
67 |
68 | ## Cancel Filter For Shield OAuth Routes
69 |
70 | `Shield OAuth` adds multiple routes to your project. `oauth/call-back` and `oauth/(:any)`, so you should register them in the category of **not applying** the shield filter. For this, you can proceed as follows you need to add the following code in the `app/Config/Filters.php` file.
71 |
72 | ```php
73 | public $globals = [
74 | 'before' => [
75 | // ...
76 | 'session' => ['except' => ['login*', 'register', 'auth/a/*', 'oauth*']],
77 | ],
78 | // ...
79 | ];
80 | ```
81 |
82 | ## Set keys
83 |
84 | Receive keys `client_id` and `client_secret` from each OAuth server.
85 | 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`.
86 |
87 | We suggest that you set the keys of each service in file **.env** instead of using **app/Config/ShieldOAuthConfig**. For example, you can proceed as follows.
88 |
89 | ```env
90 | ShieldOAuthConfig.google.client_id = Your google client_id key
91 | ShieldOAuthConfig.google.client_secret = Your google client_secret key
92 | ```
93 |
94 | > **Note**
95 | > By default, there is no file `app/Config/ShieldOAuthConfig`. It is strongly recommended to set the keys to `app/Config/ShieldOAuthConfig`. This behavior will make sure that there will be no problems for the settings you have made in case of update `Shield OAuth`. To create it, you can use the following command:
96 | >
97 | > ```console
98 | > php spark make:oauthconfig
99 | > ```
100 |
101 | You can see [How To Get Keys](get_keys.md) for instructions on how to get the keys.
102 |
103 | ```php
104 | public array $oauthConfigs = [
105 | 'github' => [
106 | 'client_id' => '8441sgsgsgsgshfgjgykgub08b6',
107 | 'client_secret' => '2336fsdgdfgdfgdfghfdhfghdhdhdhdhd',
108 | // ...
109 | ],
110 | 'google' => [
111 | 'client_id' => '95040vghjhjghjgjgj.apps.googleusercontent.com',
112 | 'client_secret' => 'fsdfsdfsgdgrdg',
113 | // ...
114 | ],
115 | // and other services...
116 | ```
117 |
118 | ## Adding all login button with OAuth in View
119 | The last step is to, You can create your own buttons in views, what is important is that the addresses should be as follows:
120 | ```html
121 | http://localhost:8080/oauth/google
122 | http://localhost:8080/oauth/github
123 | http://localhost:8080/oauth/yahoo
124 |