mediawiki/oauthclient-php
PHP OAuth client to use with Wikipedia and other MediaWiki-based wikis running the OAuth extension.
Loading...
Searching...
No Matches
MediaWiki\OAuthClient\Client Class Reference

MediaWiki OAuth client. More...

+ Inheritance diagram for MediaWiki\OAuthClient\Client:
+ Collaboration diagram for MediaWiki\OAuthClient\Client:

Public Member Functions

 __construct (ClientConfig $config, LoggerInterface $logger=null)
 
 setLogger (LoggerInterface $logger)
 @inheritDoc
 
 setExtraParam ( $key, $value)
 Set an extra param in the call that need to be signed.
 
 setExtraParams (array $params)
 
 setCallback ( $url)
 Set callback URL for OAuth handshake.
 
 initiate ()
 First part of 3-legged OAuth, get the request Token.
 
 complete (Token $requestToken, $verifyCode)
 The final leg of the OAuth handshake.
 
 identify (Token $accessToken)
 Optional step.
 
 makeOAuthCall ($token, $url, $isPost=false, array $postFields=null)
 Make a signed request to MediaWiki.
 

Static Public Member Functions

static newFromKeyAndSecret ( $url, $key, $secret)
 

Public Attributes

const IAT_TOLERANCE = 2
 

Protected Member Functions

 validateJWT ( $identity, $consumerKey, $expectedConnonicalServer, $nonce)
 

Protected Attributes

 $logger
 

Detailed Description

MediaWiki OAuth client.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\OAuthClient\Client::__construct ( ClientConfig  $config,
LoggerInterface  $logger = null 
)
Parameters
ClientConfig$config
LoggerInterface | null$logger

Member Function Documentation

◆ complete()

MediaWiki\OAuthClient\Client::complete ( Token  $requestToken,
  $verifyCode 
)

The final leg of the OAuth handshake.

Exchange the request Token from initiate() and the verification code that the user submitted back to you for an access token, which you'll use for all API calls.

Parameters
Token$requestTokenAuthorization code sent to the callback url
string$verifyCodeTemp/request token obtained from initiate, or null if this object was used and the token is already set.
Returns
Token The access token
Exceptions
ExceptionOn failed handshakes

◆ identify()

MediaWiki\OAuthClient\Client::identify ( Token  $accessToken)

Optional step.

This call the MediaWiki specific /identify method, which returns a signed statement of the authorizing user's identity. Use this if you are authenticating users in your application, and you need to know their username, groups, rights, etc in MediaWiki.

Parameters
Token$accessTokenAccess token from complete()
Returns
stdClass An object containing attributes of the user
Exceptions
ExceptionOn malformed server response or invalid JWT

◆ initiate()

MediaWiki\OAuthClient\Client::initiate ( )

First part of 3-legged OAuth, get the request Token.

Redirect your authorizing users to the redirect url, and keep track of the request token since you need to pass it into complete()

Returns
array [redirect, request/temp token]
Exceptions
ExceptionWhen the server returns an error or a malformed response

◆ makeOAuthCall()

MediaWiki\OAuthClient\Client::makeOAuthCall (   $token,
  $url,
  $isPost = false,
array  $postFields = null 
)

Make a signed request to MediaWiki.

Parameters
Token$tokenadditional token to use in signature, besides the consumer token. In most cases, this will be the access token you got from complete(), but we set it to the request token when finishing the handshake.
string$urlURL to call
bool$isPosttrue if this should be a POST request
array | null$postFieldsPOST parameters, only if $isPost is also true
Returns
string Body from the curl request
Exceptions
ExceptionOn curl failure

◆ newFromKeyAndSecret()

static MediaWiki\OAuthClient\Client::newFromKeyAndSecret (   $url,
  $key,
  $secret 
)
static
Parameters
string$url
string$key
string$secret
Returns
Client

◆ setCallback()

MediaWiki\OAuthClient\Client::setCallback (   $url)

Set callback URL for OAuth handshake.

Parameters
string$url

◆ setExtraParam()

MediaWiki\OAuthClient\Client::setExtraParam (   $key,
  $value 
)

Set an extra param in the call that need to be signed.

This should only be needed for OAuth internals.

Parameters
string$key
string$value

◆ setExtraParams()

MediaWiki\OAuthClient\Client::setExtraParams ( array  $params)
Parameters
array$params
See also
setExtraParam

◆ validateJWT()

MediaWiki\OAuthClient\Client::validateJWT (   $identity,
  $consumerKey,
  $expectedConnonicalServer,
  $nonce 
)
protected
Parameters
stdClass$identity
string$consumerKey
string$expectedConnonicalServer
string$nonce
Returns
bool

The documentation for this class was generated from the following file: