https://github.com/efureev/social
https://github.com/efureev/social
laravel socialite
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/efureev/social
- Owner: efureev
- Created: 2018-10-30T12:55:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-14T08:32:46.000Z (over 5 years ago)
- Last Synced: 2025-01-15T09:02:45.842Z (3 months ago)
- Topics: laravel, socialite
- Language: PHP
- Size: 44.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/efureev/social)
[](https://packagist.org/packages/efureev/social)
[](https://packagist.org/packages/efureev/social)## Information
Wrapper on Laravel Socialite## Install
- `composer require efureev/social`
- Run migrations: `./artisan migrate`.
- If need - make published config: `./artisan vendor:publish --tag=social`.## Basic usage
- Published resources: `php artisan vendor:publish --tag=social`
- Fill config file `social.php` into `config` dir with your social drivers:
```php
[
'vk' => [
'clientId' => env('VK_CLIENT_ID'),
'clientSecret' => env('VK_CLIENT_SECRET'),
],
'github' => [
// ...
],
// ...
],
];
```
- add into your app `.env` file variables: `VK_CLIENT_ID=...` and `VK_CLIENT_SECRET=...` with VK credentials. See in `https://vk.com/apps?act=manage`
- run migration: `php artisan migration`
- add into view (ex:`resources/views/auth/login.blade.php`):
- for list: `@include('social::list', ['socials' => app('social')->getProviders()])`
- for icons: `@include('social::icons', ['socials' => app('social')->getProviders()])`
- Done!For customizing perform - see config and docs.
## Config
### Config Props
- `redirectOnAuth` [string] redirect on address after user auth.
- `onSuccess` [\Closure|array] action on auth success. Params: \Fureev\Socialite\Two\AbstractProvider
- `drivers` [array] Driver list (`driverName => driverConfig`)
- `userClass` [string] Auth User Class (`userClass => 'App/Models/User'`)### Driver Config
- `clientId` [string] Require
- `clientSecret` [string] Require
- `enabled` [bool] Default, true.
- `label` [string] Title for view. Default, `driverName`
- `provider` [string] Class of Provider (\Fureev\Socialite\Two\AbstractProvider)
- `url_token` [string] Token URL for the provider
- `url_auth` [string] Authentication URL for the provider
- `userInfoUrl` [string] Url to get the raw user data
- `onSuccess` [\Closure|array] action on auth success. Overwrite common `onSuccess`
- `scopeSeparator` [string]
- `scopes` [array]### Example
File `config/social.php`
```php
function ($driver) {
$user = \Fureev\Social\Services\SocialAccountService::setOrGetUser($driver);return \Fureev\Social\Services\SocialAccountService::auth($user);
},
//'onSuccess' => [\App\Http\Controllers\IndexController::class, 'index'],
'drivers' => [
'gitlab' => [
'enabled' => false,
'provider' => \Fureev\Socialite\Two\GitlabProvider::class,
// 'enabled' => false,
'label' => ''
],
'vk' => [
// 'enabled' => false,
'label' => '',
'clientId' => env('VK_CLIENT_ID'),
'clientSecret' => env('VK_CLIENT_SECRET'),
],
'github' => [
'enabled' => false,
'label' => ''
],
'custom_auth' => [
'clientId' => env('SOCIAL_AUTH_CLIENT_ID'),
'clientSecret' => env('SOCIAL_AUTH_CLIENT_SECRET'),
'url_auth' => 'http://api.auth.x/auth/authorize',
'url_token' => 'http://api.auth.x/auth/token',
'userInfoUrl' => 'http://api.auth.x/users/info',
'scopeSeparator' => ',',
'scopes' => ['name','email','photo'],
'tokenFieldsExtra' => [
'grant_type' => 'authorization_code',
],
'mapFields' =>
[
'id' => 'id',
'name' => ['profile.first_name.v', new \Fureev\Socialite\Separator, 'profile.last_name.v'],
'email' => 'profile.email.v',
'avatar' => 'photo',
'nickname' => 'id',
'profileId' => 'profileId',
],
'guzzle' => [
'query' => [
'prettyPrint' => 'false',
],
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer {{%TOKEN%}}',
],
],
],
'google' => [
// 'enabled' => false,
'clientId' => env('G+_CLIENT_ID'),
'clientSecret' => env('G+_CLIENT_SECRET'),
'url_token' => 'https://accounts.google.com/o/oauth2/token',
'url_auth' => 'https://accounts.google.com/o/oauth2/auth',
'userInfoUrl' => 'https://www.googleapis.com/plus/v1/people/me?',
'label' => '',
// 'onSuccess' => [\App\Http\Controllers\HomeController::class, 'index'],
'scopeSeparator' => ' ',
'scopes' => ['openid', 'profile', 'email',],
'tokenFieldsExtra' => [
'grant_type' => 'authorization_code'
],
'mapFields' =>
[
'id' => 'id',
'name' => 'displayName',
'email' => 'emails.0.value',
'avatar' => 'image.url',
],
'guzzle' => [
'query' => [
'prettyPrint' => 'false',
],
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer {{%TOKEN%}}',
],
]
]
]
];```
File `\App\Services\SocialAccountService.php`
```php
user();$providerName = $provider->getName();
//...
}
}
```
Auto add social providers in your view:
```blade
@extends('layouts.login')@section('content')
@csrf
Пароль
@include('social::icons', ['socials' => app('social')->getProviders()])
// or
@include('social::list', ['socials' => app('social')->getProviders()])
@endsection
```