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
46 changes: 30 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
name: CI

on:
on:
push:
branches:
- "master"
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
types: [opened, synchronize, reopened]

jobs:
phpunit:
name: Tests PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
runs-on: ubuntu-latest
name: Tests PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
php: [7.3, 7.4, 8.0, 8.1]
laravel: ["8.*", "9.*"]
exclude:
- php: 7.3
laravel: "9.*"
- php: 7.4
laravel: "9.*"
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.4]
laravel: ["10.*"]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -38,12 +43,21 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
extensions: dom, curl, libxml, mbstring, zip, fileinfo, sqlite, pdo_sqlite
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer require "illuminate/support:${{ matrix.laravel }}" --prefer-dist --no-interaction
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
run: composer show -D

- name: Run Testsuite
run: ./vendor/bin/phpunit
Expand Down
52 changes: 18 additions & 34 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
name: Code-Style

on:
on:
push:
branches:
- "master"
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.php'

permissions:
contents: write

jobs:
php-code-style:
name: Check PHP code style
php-code-styling:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-code-style-composer-${{ hashFiles('composer.json') }}
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: composer:v2
extensions: dom, curl, libxml, mbstring, zip
coverage: none

- name: Install dependencies
run: |
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Run CS Fixer
run: ./vendor/bin/php-cs-fixer fix

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor/
coverage/
.phpunit.result.cache
.phpunit.cache
composer.lock
35 changes: 25 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
}
],
"require": {
"php": "^7.3|^8.0.2",
"illuminate/auth": "^8.0|^9.0",
"illuminate/console": "^8.0|^9.0",
"illuminate/encryption": "^8.0|^9.0",
"illuminate/support": "^8.0|^9.0",
"illuminate/view": "^8.0|^9.0",
"php": "^8.2",
"illuminate/auth": "^10.0",
"illuminate/console": "^10.0",
"illuminate/encryption": "^10.0",
"illuminate/support": "^10.0",
"illuminate/view": "^10.0",
"laravel/socialite": "^5.0",
"socialiteproviders/gitlab": "^3.1|^4.0",
"socialiteproviders/gitlab": "^4.0",
"socialiteproviders/dropbox": "^4.1"
},
"require-dev": {
"laravel/pint": "^1.14",
"fakerphp/faker": "^1.9.1",
"larastan/larastan": "^2.9",
"mockery/mockery": "^1.4.4",
"phpunit/phpunit": "^9.5.10",
"orchestra/testbench": "^6.15|^7.4",
"friendsofphp/php-cs-fixer": "^2.16|^3.8"
"phpunit/phpunit": "^10.5",
"orchestra/testbench": "^8.22"
},
"autoload": {
"psr-4": {
Expand All @@ -44,6 +45,20 @@
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
Expand Down
2 changes: 1 addition & 1 deletion config/identities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Encryption Key
|--------------------------------------------------------------------------
|
| The key is used by the encrypter service and should be set to a
| The key is used by the encrypter service and should be set to a
| random, 32 character string, otherwise encrypted strings will
| not be safe. By default the current APP_KEY is used.
|
Expand Down
32 changes: 12 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL"/>
<ini name="display_errors" value="1"/>
<ini name="display_startup_errors" value="1"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL"/>
<ini name="display_errors" value="1"/>
<ini name="display_startup_errors" value="1"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
14 changes: 6 additions & 8 deletions src/Auth/AuthenticatesUsersWithIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

trait AuthenticatesUsersWithIdentity
{
use RedirectsUsers, InteractsWithPreviousUrl, FindIdentity;
use FindIdentity, InteractsWithPreviousUrl, RedirectsUsers;

/**
* Redirect the user to the provider authentication page.
Expand Down Expand Up @@ -54,7 +54,7 @@ public function login(Request $request, $provider)
// GuzzleHttp\Exception\ClientException
// Client error: `POST https://gitlab.com/oauth/token` resulted in a `401 Unauthorized` response: {"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not ma (truncated...)
// $this->sendFailedLoginResponse

// If we find a registered user with the
// same identity we attempt to login

Expand All @@ -63,16 +63,15 @@ public function login(Request $request, $provider)
if (! $user) {
$this->sendFailedLoginResponse($request, $provider);
}
$this->guard()->login($user /*, $remember = false*/);

$this->guard()->login($user /* , $remember = false */);

return $this->sendLoginResponse($request);
}

/**
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
Expand All @@ -87,7 +86,6 @@ protected function sendFailedLoginResponse(Request $request, $provider)
/**
* Send the response after the user was authenticated.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendLoginResponse(Request $request)
Expand All @@ -111,7 +109,7 @@ protected function authenticated(Request $request, $user)
{
//
}

/**
* Get the guard to be used during authentication.
*
Expand Down
24 changes: 11 additions & 13 deletions src/Auth/ConnectUserIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Oneofftech\Identities\Facades\IdentityCrypt;
use Oneofftech\Identities\Facades\Identity;
use Oneofftech\Identities\Facades\IdentityCrypt;
use Oneofftech\Identities\Support\FindIdentity;
use Oneofftech\Identities\Support\InteractsWithPreviousUrl;
use Oneofftech\Identities\Support\InteractsWithAdditionalAttributes;
use Oneofftech\Identities\Support\InteractsWithPreviousUrl;

trait ConnectUserIdentity
{
use RedirectsUsers, InteractsWithPreviousUrl, InteractsWithAdditionalAttributes, FindIdentity;
use FindIdentity, InteractsWithAdditionalAttributes, InteractsWithPreviousUrl, RedirectsUsers;

/**
* Redirect the user to the Authentication provider authentication page.
Expand Down Expand Up @@ -68,29 +68,29 @@ public function connect(Request $request, $provider)

// create or update the user's identity

list($user, $identity) = DB::transaction(function () use ($user, $provider, $oauthUser) {
[$user, $identity] = DB::transaction(function () use ($user, $provider, $oauthUser) {
$identity = $this->createIdentity($user, $provider, $oauthUser);

return [$user, $identity];
});

// todo: event(new Connected($user, $identity));

return $this->sendConnectionResponse($request, $identity);
}

protected function createIdentity($user, $provider, $oauthUser)
{
return $user->identities()->updateOrCreate(
[
'provider'=> $provider,
'provider_id'=> IdentityCrypt::hash($oauthUser->getId())
'provider' => $provider,
'provider_id' => IdentityCrypt::hash($oauthUser->getId()),
],
[
'token'=> IdentityCrypt::encryptString($oauthUser->token),
'refresh_token'=> IdentityCrypt::encryptString($oauthUser->refreshToken),
'expires_at'=> $oauthUser->expiresIn ? now()->addSeconds($oauthUser->expiresIn) : null,
'registration' => false,
'token' => IdentityCrypt::encryptString($oauthUser->token),
'refresh_token' => IdentityCrypt::encryptString($oauthUser->refreshToken),
'expires_at' => $oauthUser->expiresIn ? now()->addSeconds($oauthUser->expiresIn) : null,
'registration' => false,
]
);
}
Expand All @@ -111,8 +111,6 @@ protected function sendConnectionResponse(Request $request, $identity)
*
* @param mixed $user
* @param mixed $identity
* @param array $attributes
* @param \Illuminate\Http\Request $request
* @return mixed
*/
protected function connected($user, $identity, array $attributes, Request $request)
Expand Down
Loading
Loading