Skip to content

Commit

Permalink
Merge pull request #2 from maxerism/custom-endpoint
Browse files Browse the repository at this point in the history
Add custom endpoint support
  • Loading branch information
aneip committed Mar 20, 2024
2 parents 9470347 + acec1ef commit 5c3d5f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
KATSANA Socialite Provider
==============
# KATSANA Socialite Provider

[![Build Status](https://travis-ci.org/katsana/katsana-socialite.svg?branch=1.0)](https://travis-ci.org/katsana/katsana-socialite)
[![Latest Stable Version](https://poser.pugx.org/katsana/socialite/v/stable)](https://packagist.org/packages/katsana/socialite)
[![Total Downloads](https://poser.pugx.org/katsana/socialite/downloads)](https://packagist.org/packages/katsana/socialite)
[![Latest Unstable Version](https://poser.pugx.org/katsana/socialite/v/unstable)](https://packagist.org/packages/katsana/socialite)
[![License](https://poser.pugx.org/katsana/socialite/license)](https://packagist.org/packages/katsana/socialite)


* [Installation](#installation)

- [Installation](#installation)

## Installation

To install through composer, simply put the following in your `composer.json` file:

```json
{
"require": {
"katsana/socialite": "^1.0"
}
"require": {
"katsana/socialite": "^1.0"
}
}
```

Expand All @@ -31,7 +28,7 @@ KATSANA Socialite is built using [SocialiteProviders](http://socialiteproviders.

```php
'providers' => [

// Other service providers...
Katsana\ServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
Expand All @@ -55,6 +52,12 @@ You will also need to add credentials for the OAuth services your application ut
'client_id' => 'your-katsana-client-id',
'client_secret' => 'your-katsana-client-secret',
'redirect' => 'http://your-callback-url',
//Optional
'endpoints'=>[
'api' => 'http://katsana-api-endpoint',
'oauth' => 'http://katsana-outh-endpoint',
],
'includes'=>'extra_profile_data',
],
```

Expand Down Expand Up @@ -142,7 +145,6 @@ The `stateless` method may be used to disable session state verification. This i
return Socialite::driver('katsana')->stateless()->user();
```


#### Retrieving User Details

Once you have a user instance, you can grab a few more details about the user:
Expand Down
12 changes: 8 additions & 4 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Container\Container;
use Katsana\Sdk\Client;
use Katsana\Sdk\Query;
use Laravel\Socialite\Two\ProviderInterface;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;

Expand Down Expand Up @@ -83,7 +84,7 @@ protected function getEnvironmentEndpoint(?string $group = null): ?string
return static::$endpoints[$environment];
}

return static::$endpoints[$environment][$group] ?? null;
return data_get($this->getConfig('endpoints'), $group) ?? static::$endpoints[$environment][$group] ?? null;
}

/**
Expand All @@ -96,7 +97,8 @@ protected function getEnvironmentEndpoint(?string $group = null): ?string
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase(
$this->getEnvironmentEndpoint('oauth').'/authorize', $state
$this->getEnvironmentEndpoint('oauth').'/authorize',
$state
);
}

Expand All @@ -119,11 +121,13 @@ protected function getTokenUrl()
*/
protected function getUserByToken($token)
{
$includes= $this->getConfig('includes')?Query::includes($this->getConfig('includes')):null;

return $this->sdkClient()
->useCustomApiEndpoint($this->getEnvironmentEndpoint('api'))
->setAccessToken($token)
->uses('Profile')
->get()
->get($includes)
->toArray();
}

Expand Down Expand Up @@ -165,7 +169,7 @@ protected function getTokenFields($code)
*/
public static function additionalConfigKeys()
{
return ['environment'];
return ['environment','endpoints','includes'];
}

/**
Expand Down

0 comments on commit 5c3d5f2

Please sign in to comment.