Skip to content

Commit

Permalink
drop php v8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurk91 committed Jan 15, 2023
1 parent 95ebfa1 commit d37f321
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 101 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{scss,css,ts,js,cjs,html,json,vue,yml,yaml}]
indent_size = 2
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
* text=auto

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.styleci.yml export-ignore
/.editorconfig export-ignore
/CHANGELOG.md export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
16 changes: 11 additions & 5 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ Please read and understand the contribution guide before creating an issue or pu

If the project maintainer has any additional requirements, you will find them listed here.


- **[PSR-2 Coding Standard.](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** The easiest way to apply the conventions is to install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
- **[PSR-2 Coding Standard.](https://www.php-fig.org/psr/psr-2/)**
- The easiest way to apply the conventions is to
install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
- **Add tests!** Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour.** Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle.** We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **Document any change in behaviour.** Make sure the `README.md` and any other relevant documentation are kept
up-to-date.
- **Consider our release cycle.** We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is
not an option.
- **Create feature branches.** Don't ask us to pull from your master branch.
- **One pull request per feature.** If you want to do more than one thing, send multiple pull requests.
- **Send coherent history.** Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
- **Send coherent history.** Make sure each individual commit in your pull request is meaningful. If you had to make
multiple intermediate commits while developing,
please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages)
before submitting.

**Happy coding!**
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1]
php: [8.1, 8.2]

name: php v${{ matrix.php }}

Expand All @@ -30,11 +30,11 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
ini-values: error_reporting=E_ALL
coverage: pcov

- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress
run: composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: composer test -- --coverage-clover=coverage.xml

run: composer test -- --coverage-clover=coverage.xml
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor
composer.lock
.phpunit.result.cache
.phpunit.result.cache
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

All notable changes to `laravel-passport-social-grant` will be documented in this file:
All notable changes to this package will be documented in this file:

## 3.1.0

* Drop php 8.0 support
* Test on php 8.2 and Laravel 10

## 3.0.0

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Ilya Sakovich
Copyright (c) 2023 Ilya Sakovich

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The package will automatically register itself.

As the first step, you need to implement `SocialUserResolverInterface`:

Here is an example using [Socialite](https://laravel.com/docs/9.x/socialite) -

```php
<?php

Expand All @@ -35,21 +37,26 @@ namespace App\Resolvers;
use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\User as ProviderUser;

class SocialUserResolver implements SocialUserResolverInterface
{
/**
* Resolve user by provider credentials.
*
* @param string $provider
* @param string $accessToken
*
* @return Authenticatable|null
*/
public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable
{
// Return the user that corresponds to provided credentials.
// If the credentials are invalid, then return NULL.
$providerUser = Socialite::driver($provider)->userFromToken($accessToken);

return $this->findOrCreateUser($provider, $providerUser);;
}

protected function findOrCreateUser(string $provider, ProviderUser $providerUser): ?Authenticatable
{
// todo your logic here
// $email = $providerUser->getEmail();
}
}
```
Expand All @@ -70,7 +77,7 @@ use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* All of the container bindings that should be registered.
* All the container bindings that should be registered.
*
* @var array
*/
Expand Down Expand Up @@ -113,7 +120,7 @@ axios.post('/oauth/token', {
});
```

Example of usage with `guzzle`:
Example of usage with `guzzlehttp/guzzle`:

```php
<?php
Expand Down Expand Up @@ -163,7 +170,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Credits

Expand Down
90 changes: 51 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
{
"name": "coderello/laravel-passport-social-grant",
"description": "Social Grant for Laravel Passport",
"keywords": ["laravel", "passport", "social", "network", "grant", "oauth"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Ilya Sakovich",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"laravel/passport": "^11.3.0"
},
"require-dev": {
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^7.13.0",
"laminas/laminas-diactoros": "^2.8"
},
"autoload": {
"psr-4": {
"Coderello\\SocialGrant\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Coderello\\SocialGrant\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always"
},
"extra": {
"laravel": {
"providers": [
"Coderello\\SocialGrant\\Providers\\SocialGrantServiceProvider"
]
}
"name": "coderello/laravel-passport-social-grant",
"description": "Social Grant for Laravel Passport",
"keywords": [
"laravel",
"passport",
"social",
"network",
"grant",
"oauth"
],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Ilya Sakovich",
"email": "[email protected]"
}
],
"require": {
"php": "^8.1",
"laravel/passport": "^11.3.0"
},
"require-dev": {
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^7.13.0 || ^8.0",
"laminas/laminas-diactoros": "^2.8"
},
"autoload": {
"psr-4": {
"Coderello\\SocialGrant\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Coderello\\SocialGrant\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit --testdox --colors=always"
},
"extra": {
"laravel": {
"providers": [
"Coderello\\SocialGrant\\Providers\\SocialGrantServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
21 changes: 5 additions & 16 deletions src/Grants/SocialGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Coderello\SocialGrant\Grants;

use DateInterval;
use League\OAuth2\Server\RequestEvent;
use Psr\Http\Message\ServerRequestInterface;
use League\OAuth2\Server\Grant\AbstractGrant;
Expand All @@ -15,25 +16,17 @@ class SocialGrant extends AbstractGrant
{
/**
* Social user resolver instance.
*
* @var SocialUserResolverInterface
*/
protected $resolver;
protected SocialUserResolverInterface $resolver;

/**
* SocialGrant constructor.
*
* @param SocialUserResolverInterface $resolver
* @param RefreshTokenRepositoryInterface $refreshTokenRepository
*/
public function __construct(
SocialUserResolverInterface $resolver,
RefreshTokenRepositoryInterface $refreshTokenRepository
) {
$this->resolver = $resolver;
$this->setRefreshTokenRepository($refreshTokenRepository);

$this->refreshTokenTTL = new \DateInterval('P1M');
$this->refreshTokenTTL = new DateInterval('P1M');
}

/**
Expand All @@ -42,7 +35,7 @@ public function __construct(
public function respondToAccessTokenRequest(
ServerRequestInterface $request,
ResponseTypeInterface $responseType,
\DateInterval $accessTokenTTL
DateInterval $accessTokenTTL
): ResponseTypeInterface {
// Validate request
$client = $this->validateClient($request);
Expand Down Expand Up @@ -70,11 +63,7 @@ public function respondToAccessTokenRequest(
/**
* Validate server request and get the user entity.
*
* @param ServerRequestInterface $request
*
* @throw OAuthServerException
*
* @return UserEntity
* @throws OAuthServerException
*/
public function validateUser(ServerRequestInterface $request): UserEntity
{
Expand Down
22 changes: 1 addition & 21 deletions src/Providers/SocialGrantServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@

class SocialGrantServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(): void
{
//
}

/**
* Register the application services.
*
* @return void
*/
public function register(): void
{
$this->app->resolving(AuthorizationServer::class, function (AuthorizationServer $server) {
Expand All @@ -36,11 +21,6 @@ public function register(): void
});
}

/**
* Create and configure a Social grant instance.
*
* @return SocialGrant
*/
protected function makeSocialGrant(): SocialGrant
{
$grant = new SocialGrant(
Expand All @@ -52,4 +32,4 @@ protected function makeSocialGrant(): SocialGrant

return $grant;
}
}
}
5 changes: 0 additions & 5 deletions src/Resolvers/SocialUserResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ interface SocialUserResolverInterface
{
/**
* Resolve user by provider credentials.
*
* @param string $provider
* @param string $accessToken
*
* @return Authenticatable|null
*/
public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable;
}

0 comments on commit d37f321

Please sign in to comment.