-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,7 @@ parameters: | |
src/Sage: '[email protected]:SocialiteProviders/Sage.git' | ||
src/SalesForce: '[email protected]:SocialiteProviders/SalesForce.git' | ||
src/Salesloft: '[email protected]:SocialiteProviders/Salesloft.git' | ||
src/Salla: '[email protected]:SocialiteProviders/Salla.git' | ||
src/Saml2: '[email protected]:SocialiteProviders/Saml2.git' | ||
src/SciStarter: '[email protected]:SocialiteProviders/SciStarter.git' | ||
src/SharePoint: '[email protected]:SocialiteProviders/SharePoint.git' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Salla; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use Illuminate\Support\Arr; | ||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
use SocialiteProviders\Manager\OAuth2\User; | ||
|
||
class Provider extends AbstractProvider | ||
{ | ||
public const IDENTIFIER = 'SALLA'; | ||
|
||
/** | ||
* The separating character for the requested scopes. | ||
* | ||
* @var string | ||
*/ | ||
protected $scopeSeparator = ' '; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = [ | ||
'offline_access' | ||
]; | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getAuthUrl($state) | ||
{ | ||
return $this->buildAuthUrlFromBase( | ||
'https://accounts.salla.sa/oauth2/auth', | ||
$state | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenUrl() | ||
{ | ||
return 'https://accounts.salla.sa/oauth2/token'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUserByToken($token) | ||
{ | ||
$response = $this->getHttpClient()->get( | ||
'https://accounts.salla.sa/oauth2/user/info', | ||
[ | ||
RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer '.$token, | ||
], | ||
] | ||
); | ||
|
||
return json_decode((string) $response->getBody(), true)['data']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function mapUserToObject(array $user) | ||
{ | ||
return (new User)->setRaw($user)->map([ | ||
'id' => $user['id'], | ||
'name' => $user['name'] ?? null, | ||
'email' => $user['email'] ?? null, | ||
'mobile' => $user['mobile'] ?? null, | ||
'avatar' => $user['merchant']['avatar'] ?? null, | ||
'domain' => $user['merchant']['domain'] ?? null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Salla | ||
|
||
```bash | ||
composer require socialiteproviders/salla | ||
``` | ||
## Create Account & App on Salla Partner | ||
First you need to register account on [Salla Partners Portal](https://salla.partners/) and create your app to get credentials `client_id` & `client_secret`. | ||
See the docs for more info [Salla API Docs](https://docs.salla.dev) | ||
|
||
## Installation & Basic Usage | ||
|
||
Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below. | ||
|
||
### Add configuration to `config/services.php` | ||
|
||
```php | ||
'salla' => [ | ||
'client_id' => env('SALLA_CLIENT_ID'), | ||
'client_secret' => env('SALLA_CLIENT_SECRET'), | ||
'redirect' => env('SALLA_REDIRECT_URI') | ||
], | ||
``` | ||
|
||
### Add provider event listener | ||
|
||
#### Laravel 11+ | ||
|
||
In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method. | ||
|
||
* Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers. | ||
|
||
```php | ||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) { | ||
$event->extendSocialite('salla', \SocialiteProviders\Salla\Provider::class); | ||
}); | ||
``` | ||
<details> | ||
<summary> | ||
Laravel 10 or below | ||
</summary> | ||
Configure the package's listener to listen for `SocialiteWasCalled` events. | ||
|
||
Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions. | ||
|
||
```php | ||
protected $listen = [ | ||
\SocialiteProviders\Manager\SocialiteWasCalled::class => [ | ||
// ... other providers | ||
\SocialiteProviders\Salla\SallaExtendSocialite::class.'@handle', | ||
], | ||
]; | ||
``` | ||
</details> | ||
|
||
### Usage | ||
|
||
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed): | ||
|
||
```php | ||
return Socialite::driver('salla')->redirect(); | ||
``` | ||
After redirect, You may return User instance: | ||
```php | ||
return Socialite::driver('salla')->user(); | ||
``` | ||
|
||
### Returned User fields | ||
|
||
- ``id`` | ||
- ``name`` | ||
- ``email`` | ||
- ``mobile`` | ||
- ``role`` | ||
- ``merchant`` | ||
- - ``id`` | ||
- - ``username`` | ||
- - ``name`` | ||
- - ``avatar`` | ||
- - ``plan`` | ||
- - ``status`` | ||
- - ``domain`` | ||
- - ``tax_number`` | ||
- - ``commercial_number`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace SocialiteProviders\Salla; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class SallaExtendSocialite | ||
{ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled): void | ||
{ | ||
$socialiteWasCalled->extendSocialite('salla', Provider::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "socialiteproviders/salla", | ||
"description": "Salla Ecommerce OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"keywords": [ | ||
"salla", | ||
"ecommerce", | ||
"laravel", | ||
"provider", | ||
"socialite" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Ghazi Mohammed", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/socialiteproviders/providers/issues", | ||
"source": "https://github.com/socialiteproviders/providers", | ||
"docs": "https://socialiteproviders.com/salla" | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"socialiteproviders/manager": "^4.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SocialiteProviders\\Salla\\": "" | ||
} | ||
} | ||
} |