Comments (6)
You will need to implement each of those methods for this class to function properly. Otherwise, you will need to find one of the existing provider specific implementations to use as your base class then override the single method you are interested in at this time.
from oauth1-client.
Well the thing is I need to override the getTokenCredentials
-method completely and my Server
class should replace the League\OAuth1\Client\Server\Server
.
My Providers would then extend MyNamespace\OAuth1\Server
instead of League\OAuth1\Client\Server\Server
.
So how do I replace the League Server with my own Server class to prevent this stupid solution I have at the moment?
from oauth1-client.
Can you describe your use case here a bit more? How many provider specific implementations are you planning to build? Do they share some logic and behavior? If so, what?
from oauth1-client.
This would be used for all the OAuth1 Providers at https://github.com/SocialiteProviders. All OAuth1 Providers look pretty much like this.
<?php
namespace SocialiteProviders\Twitter;
use League\OAuth1\Client\Credentials\CredentialsException;
use SocialiteProviders\Manager\OAuth1\User;
class Provider extends AbstractProvider
{
/**
* Unique Provider Identifier.
*/
const PROVIDER_IDENTIFIER = 'TWITTER';
/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user['extra'])->map(
[
'id' => $user['id'],
'nickname' => $user['nickname'],
'name' => $user['name'],
'email' => $user['email'],
'avatar' => $user['avatar'],
]
);
}
}
<?php
namespace SocialiteProviders\Manager\OAuth1;
use GuzzleHttp\ClientInterface;
use Laravel\Socialite\One\InvalidStateException;
use SocialiteProviders\Manager\ConfigTrait;
use SocialiteProviders\Manager\SocialiteWasCalled;
abstract class AbstractProvider extends \Laravel\Socialite\One\AbstractProvider
{
protected $credentialsResponseBody;
public function user()
{
if (!$this->hasNecessaryVerifier()) {
throw new \InvalidArgumentException('Invalid request. Missing OAuth verifier.');
}
$token = $this->getToken();
$tokenCredentials = $token['tokenCredentials'];
$user = $this->mapUserToObject((array) $this->server->getUserDetails($tokenCredentials));
$user->setToken($tokenCredentials->getIdentifier(), $tokenCredentials->getSecret());
if ($user instanceof User) {
parse_str($token['credentialsResponseBody'], $credentialsResponseBody);
if (!$credentialsResponseBody || !is_array($credentialsResponseBody)) {
throw new CredentialsException('Unable to parse token credentials response.');
}
$user->setAccessTokenResponseBody($credentialsResponseBody);
}
return $user;
}
}
<?php
namespace SocialiteProviders\Manager\OAuth1;
use GuzzleHttp\Exception\BadResponseException;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use League\OAuth1\Client\Credentials\TokenCredentials;
class Server extends \League\OAuth1\Client\Server\Server
{
public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier)
{
if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) {
throw new \InvalidArgumentException(
'Temporary identifier passed back by server does not match that of stored temporary credentials.
Potential man-in-the-middle.'
);
}
$uri = $this->urlTokenCredentials();
$bodyParameters = array('oauth_verifier' => $verifier);
$client = $this->createHttpClient();
$headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters);
try {
$response = $client->post($uri, $headers, $bodyParameters)->send();
} catch (BadResponseException $e) {
return $this->handleTokenCredentialsBadResponse($e);
}
return [
'tokenCredentials' => $this->createTokenCredentials($response->getBody()),
'credentialsResponseBody' => $response->getBody()
];
}
/**
* {@inheritdoc}
*/
public function urlTemporaryCredentials()
{
//
}
/**
* {@inheritdoc}
*/
public function urlAuthorization()
{
//
}
/**
* {@inheritdoc}
*/
public function urlTokenCredentials()
{
//
}
/**
* {@inheritdoc}
*/
public function urlUserDetails()
{
//
}
/**
* {@inheritdoc}
*/
public function userDetails($data, TokenCredentials $tokenCredentials)
{
//
}
/**
* {@inheritdoc}
*/
public function userUid($data, TokenCredentials $tokenCredentials)
{
//
}
/**
* {@inheritdoc}
*/
public function userEmail($data, TokenCredentials $tokenCredentials)
{
//
}
/**
* {@inheritdoc}
*/
public function userScreenName($data, TokenCredentials $tokenCredentials)
{
//
}
}
I need the custom Server class because I need to grab the response received after requesting the access token.
P. S.: All of the above code is working at the moment but I find this solution nasty because of all the empty methods.
from oauth1-client.
Hi @DraperStudio, I am trying to understand the issue here.
As I understand it, your problem is that you have a bunch of empty methods in your implementations?
If so, there's really not much we can do about that in v1 as this would seriously break BC. In V2 this has been refactored and it might just be worth waiting out for this.
from oauth1-client.
As far as replacing the League's server class, I'm not sure if I'm missing what you're asking here as well. I don't believe anything else would be required other than you extending that class in your own custom implementation (for the getTokenCredentials()
method you described).
Going to close off the issue now, feel free to reopen if you need further clarification or I've missed what you're asking :)
from oauth1-client.
Related Issues (20)
- Twitter could not authenticate temporary credentials HOT 2
- Class 'Symfony\Component\EventDispatcher\Event' not found HOT 3
- Problem with league/oauth1-client version 1.6.2 upgrading to 1.7 HOT 3
- Guzzle HTTP Client configuration HOT 1
- Composer deprecation notices
- Composer psr-4 autoloading HOT 1
- Breaking change for v1.8.0 HOT 11
- baseString composition fails when port is specified in URI HOT 2
- [PHP 8] Warning on EncodesUrl HOT 17
- Options for authorization URL HOT 3
- Avoid "functions" from dependencies HOT 3
- Trello "An unknown application" HOT 2
- Last release is broken HOT 2
- SignatureInterface is not correctly imported after recent Twitter server changes
- Invalid oauth_verifier parameter
- PHP 8.1 support
- Not sure how to configure signature element
- Magento provider no longer works (outdated hash algorithm)
- Invalid auth/bad request Etsy
- Don't support proxy? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oauth1-client.