Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: coderello/laravel-passport-social-grant
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.0.1
Choose a base ref
...
head repository: coderello/laravel-passport-social-grant
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 14 files changed
  • 4 contributors

Commits on Jul 22, 2020

  1. chore: speedup ci

    Lets use composer v2
    ankurk91 authored Jul 22, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9f443ac View commit details

Commits on Sep 9, 2020

  1. Add support for laravel passport 10 (#35)

    * Add support for laravel passport 10
    
    * Allow test-bench 6
    
    * ❎ Ignore idea, and composer.phar
    
    Signed-off-by: Lloric Mayuga Garcia <[email protected]>
    
    * 🐛 Fix missing
    
    Signed-off-by: Lloric Mayuga Garcia <[email protected]>
    
    * ☕ run --migrate-configuration
    
    Signed-off-by: Lloric Mayuga Garcia <[email protected]>
    
    * 🔒 Set verbose="true"
    
    Signed-off-by: Lloric Mayuga Garcia <[email protected]>
    
    * Fix
    
    Co-authored-by: ankurk91 <[email protected]>
    lloricode and ankurk91 authored Sep 9, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2b55a31 View commit details

Commits on Dec 14, 2020

  1. Add php 8 support #39 (#40)

    ankurk91 authored Dec 14, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fc4ab16 View commit details

Commits on Dec 25, 2021

  1. Drop passport v9 support (#45)

    Drop support for php v7.3 (EOL)
    Test on php 8.1
    ankurk91 authored Dec 25, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ae25335 View commit details

Commits on Nov 17, 2022

  1. Support Passport 11 (#48)

    ankurk91 authored Nov 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    95ebfa1 View commit details

Commits on Jan 15, 2023

  1. drop php v8.0

    ankurk91 committed Jan 15, 2023
    Copy the full SHA
    d37f321 View commit details

Commits on Apr 18, 2023

  1. fix failing test

    ankurk91 committed Apr 18, 2023
    Copy the full SHA
    f69c7a7 View commit details
  2. fix: matrix on ci

    ankurk91 committed Apr 18, 2023
    Copy the full SHA
    c7d0f56 View commit details

Commits on Mar 20, 2024

  1. Add support for Laravel 11 (#49)

    * Add laravel/passport ^12.0 as compatible version
    
    * Test on Laravel 11 and drop Laravel 9 testing
    
    Laravel 9 is not supported anymore, so also dropping tests on that
    version.
    
    * Document changes
    
    * drop support for php 8.1
    
    ---------
    
    Co-authored-by: ankurk91 <[email protected]>
    kverstae and ankurk91 authored Mar 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    958d5d5 View commit details
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
@@ -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!**
26 changes: 11 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ on:
branches:
- master
- dev
- next
pull_request:
schedule:
- cron: '0 0 1 * *'
@@ -14,34 +13,31 @@ jobs:
test:

runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4]
composer-flag: [prefer-lowest, prefer-stable]
php: [ 8.2, 8.3 ]
laravel: [ 10, 11 ]

name: php v${{ matrix.php }} - ${{ matrix.composer-flag }}
name: PHP ${{ matrix.php }} - Laravel v${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: php-v${{ matrix.php }}-composer-${{ hashFiles('composer.lock') }}
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: xdebug
ini-values: error_reporting=E_ALL
coverage: pcov

- name: Install dependencies
run: composer update --${{ matrix.composer-flag }} --no-interaction
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
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
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# 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.2.0

* Add support for Laravel 11
* Drop support for Laravel 9

## 3.1.0

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

## 3.0.0

* Drop support for Passport v6.x and v7.x
* Bump min php version to 7.2

## 1.0.0

- Initial release
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) 2024 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
78 changes: 47 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
# Laravel Passport Social Grant

[![Packagist](https://badgen.net/packagist/v/coderello/laravel-passport-social-grant)](https://packagist.org/packages/coderello/laravel-passport-social-grant)
[![GitHub tag](https://badgen.net/github/tag/coderello/laravel-passport-social-grant)](https://github.com/coderello/laravel-passport-social-grant/releases)
[![GitHub tag](https://badgen.net/github/tag/coderello/laravel-passport-social-grant)](https://github.com/coderello/laravel-passport-social-grant/tags)
[![License](https://badgen.net/packagist/license/coderello/laravel-passport-social-grant)](LICENSE.md)
[![Downloads](https://badgen.net/packagist/dt/coderello/laravel-passport-social-grant)](https://packagist.org/packages/coderello/laravel-passport-social-grant/stats)
[![tests](https://github.com/coderello/laravel-passport-social-grant/workflows/tests/badge.svg)](https://github.com/coderello/laravel-passport-social-grant/actions)

This package adds a social grant for your OAuth2 server. It can be useful if have an API and want to provide the ability for your users to login/register through social networks.
This package adds a social grant for your OAuth2 server. It can be useful if have an API and want to provide the ability
for your users to login/register through social networks.

As a result you will be able to exchange `access_token`, issued by the OAuth2 server of any social provider, to `access_token` and `refresh_token` issued by your own OAuth2 server.
As a result you will be able to exchange `access_token`, issued by the OAuth2 server of any social provider,
to `access_token` and `refresh_token` issued by your own OAuth2 server.
You will receive this `access_token` and return the user instance that corresponds to it on your own.

## Installation

You can install this package via composer using this command:

```bash
composer require coderello/laravel-passport-social-grant
```

The package will automatically register itself.

## Configuring

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

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

```php
<?php

@@ -29,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();
}
}
```
@@ -64,9 +77,7 @@ use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* All of the container bindings that should be registered.
*
* @var array
* All the container bindings that should be registered.
*/
public $bindings = [
SocialUserResolverInterface::class => SocialUserResolver::class,
@@ -77,6 +88,7 @@ class AppServiceProvider extends ServiceProvider
You are done!

## Usage

Example of usage with `axios`:

```javascript
@@ -86,27 +98,27 @@ axios.post('/oauth/token', {
client_secret: clientSecret, // client secret
provider: providerName, // name of provider (e.g., 'facebook', 'google' etc.)
access_token: providerAccessToken, // access token issued by specified provider
})
.then((response) => {
const {
access_token: accessToken,
expires_in: expiresIn,
refresh_token: refreshToken,
} = response.data;

// success logic
})
.catch((error) => {
const {
message,
hint,
} = error.response.data;

// error logic
});
})
.then((response) => {
const {
access_token: accessToken,
expires_in: expiresIn,
refresh_token: refreshToken,
} = response.data;

// success logic
})
.catch((error) => {
const {
message,
hint,
} = error.response.data;

// error logic
});
```

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

```php
<?php
@@ -143,17 +155,20 @@ if ($response->getStatusCode() === Response::HTTP_OK) {
```

## Testing

You can run the tests with:

```bash
composer test
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

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

## Credits

@@ -162,4 +177,5 @@ Created by [Illia Sakovich](https://github.com/hivokas)
Maintained by [Ankur Kumar](https://github.com/ankurk91)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
Loading