Documentation

OpenStreetmap extends OAuth1Provider
in package
implements UserInfo

OpenStreetmap OAuth1 (deprecated)

https://github.com/openstreetmap/operations/issues/867

Tags
link
https://wiki.openstreetmap.org/wiki/API
link
https://wiki.openstreetmap.org/wiki/OAuth

Table of Contents

Interfaces

UserInfo
Indicates whether the service can provide information about the currently authenticated user, usually via a "/me", "/user" or "/tokeninfo" endpoint.

Constants

IDENTIFIER  = 'OPENSTREETMAP'

Properties

$accessTokenURL  : string
$apiDocs  : string|null
$apiURL  : string
$applicationURL  : string|null
$authorizationURL  : string
$http  : ClientInterface
The PSR-18 HTTP client
$logger  : LoggerInterface
A PSR-3 logger
$name  : string
The name of the provider/class
$options  : OAuthOptions|SettingsContainerInterface
The options instance
$requestFactory  : RequestFactoryInterface
A PSR-17 request factory
$requestTokenURL  : string
The request token URL
$revokeURL  : string
An optional URL for application side token revocation
$storage  : OAuthStorageInterface
A storage instance
$streamFactory  : StreamFactoryInterface
A PSR-17 stream factory
$uriFactory  : UriFactoryInterface
A PSR-17 URI factory
$userRevokeURL  : string|null
An optional link to the page where a user can revoke access tokens

Methods

__construct()  : mixed
OAuthProvider constructor.
getAccessToken()  : AccessToken
Obtains an OAuth1 access token with the given $token and $verifier and returns an AccessToken object.
getAccessTokenFromStorage()  : AccessToken
Gets an access token from the current OAuthStorageInterface (shorthand/convenience)
getApiDocURL()  : string|null
Returns the link to the provider's API docs, or null if the value is not set
getApplicationURL()  : string|null
Returns the link to the provider's credential registration/application page, or null if the value is not set
getAuthorizationURL()  : UriInterface
Prepares the URL with optional $params which redirects to the provider's authorization prompt and returns a PSR-7 UriInterface with all necessary parameters set.
getName()  : string
Returns the name of the provider/class
getRequestAuthorization()  : RequestInterface
Authorizes the $request with the credentials from the given $token and returns a PSR-7 RequestInterface with all necessary headers and/or parameters set
getStorage()  : OAuthStorageInterface
Returns the current OAuthStorageInterface
getUserRevokeURL()  : string|null
Returns the link to the page where a user can revoke access tokens, or null if the value is not set
InvalidateAccessToken()  : bool
implements TokenInvalidate
me()  : AuthenticatedUser
Returns information about the currently authenticated user (usually a /me or /user endpoint).
request()  : ResponseInterface
Prepares an API request to $path with the given parameters, gets authorization, fires the request and returns a PSR-7 ResponseInterface with the corresponding API response
sendRequest()  : ResponseInterface
setLogger()  : static
Sets an optional PSR-3 LoggerInterface
setRequestFactory()  : static
Sets an optional PSR-17 RequestFactoryInterface
setStorage()  : static
Sets an optional OAuthStorageInterface
setStreamFactory()  : static
Sets an optional PSR-17 StreamFactoryInterface
setUriFactory()  : static
Sets an optional PSR-17 UriFactoryInterface
storeAccessToken()  : static
Sets an access token in the current OAuthStorageInterface (shorthand/convenience)
addBasicAuthHeader()  : RequestInterface
Adds an "Authorization: Basic <base64(key:secret)>" header to the given request
cleanBodyParams()  : array<string, string>
Cleans an array of body parameters
cleanQueryParams()  : array<string, string>
Cleans an array of query parameters
construct()  : void
A replacement constructor that you can call in extended classes, so that you don't have to implement the monstrous original `__construct()`
createAccessToken()  : AccessToken
Creates an access token with the provider set to $this->name
getAccessTokenRequestHeaderParams()  : array<string, scalar>
Prepares the header params for the access token request
getMeResponseData()  : array<int|string, mixed>
fetches the provider's "me" endpoint and returns the JSON data as an array
getRequestHeaders()  : array<string, string>
Prepare request headers
getRequestTarget()  : string
Determine the request target from the given URI (path segment or URL) with respect to $apiURL, anything except host and path will be ignored, scheme will always be set to "https".
getRequestTokenRequestParams()  : array<string, scalar>
prepares the parameters for the request token request header
getRequestURL()  : string
Prepares the request URL
getSignature()  : string
Generates a request signature
handleMeResponseError()  : void
handles errors for the `me()` endpoints - one horrible block of code to catch them all
nonce()  : string
returns a 32 byte random string (in hexadecimal representation) for use as a nonce
parseTokenResponse()  : AccessToken
Parses the response from a request to the token endpoint
sendAccessTokenRequest()  : ResponseInterface
Sends the access token request
sendMeRequest()  : ResponseInterface
prepares and sends the request to the provider's "me" endpoint and returns a ResponseInterface
sendRequestTokenRequest()  : ResponseInterface
Sends a request to the request token endpoint
setAuthorizationHeader()  : RequestInterface
Adds the "Authorization" header to the given `RequestInterface` using the given array or parameters
setRequestBody()  : RequestInterface
Prepares the request body and sets it in the given RequestInterface, along with a Content-Length header

Constants

Properties

$accessTokenURL

protected string $accessTokenURL = 'https://www.openstreetmap.org/oauth/access_token'

$apiDocs

protected string|null $apiDocs = 'https://wiki.openstreetmap.org/wiki/API'

$apiURL

protected string $apiURL = 'https://api.openstreetmap.org'

$applicationURL

protected string|null $applicationURL = 'https://www.openstreetmap.org/user/{USERNAME}/oauth_clients'

$authorizationURL

protected string $authorizationURL = 'https://www.openstreetmap.org/oauth/authorize'

$http

The PSR-18 HTTP client

protected ClientInterface $http

$name

The name of the provider/class

protected string $name = ''

$requestFactory

A PSR-17 request factory

protected RequestFactoryInterface $requestFactory

$requestTokenURL

The request token URL

protected string $requestTokenURL = 'https://www.openstreetmap.org/oauth/request_token'

$streamFactory

A PSR-17 stream factory

protected StreamFactoryInterface $streamFactory

$uriFactory

A PSR-17 URI factory

protected UriFactoryInterface $uriFactory

$userRevokeURL

An optional link to the page where a user can revoke access tokens

protected string|null $userRevokeURL = null

Methods

__construct()

OAuthProvider constructor.

public final __construct(OAuthOptions|SettingsContainerInterface $options, ClientInterface $http, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory, UriFactoryInterface $uriFactory[, OAuthStorageInterface $storage = new MemoryStorage() ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
$options : OAuthOptions|SettingsContainerInterface
$http : ClientInterface
$requestFactory : RequestFactoryInterface
$streamFactory : StreamFactoryInterface
$uriFactory : UriFactoryInterface
$storage : OAuthStorageInterface = new MemoryStorage()
$logger : LoggerInterface = new NullLogger()

getAccessToken()

Obtains an OAuth1 access token with the given $token and $verifier and returns an AccessToken object.

public getAccessToken(string $requestToken, string $verifier) : AccessToken
Parameters
$requestToken : string
$verifier : string
Tags
inheritDoc
throws
ProviderException
Return values
AccessToken

getAccessTokenFromStorage()

Gets an access token from the current OAuthStorageInterface (shorthand/convenience)

public final getAccessTokenFromStorage() : AccessToken
Tags
codeCoverageIgnore
Return values
AccessToken

getApiDocURL()

Returns the link to the provider's API docs, or null if the value is not set

public final getApiDocURL() : string|null
Tags
codeCoverageIgnore
Return values
string|null

getApplicationURL()

Returns the link to the provider's credential registration/application page, or null if the value is not set

public final getApplicationURL() : string|null
Tags
codeCoverageIgnore
Return values
string|null

getAuthorizationURL()

Prepares the URL with optional $params which redirects to the provider's authorization prompt and returns a PSR-7 UriInterface with all necessary parameters set.

public getAuthorizationURL([array<string, scalar>|null $params = null ][, array<string|int, mixed>|null $scopes = null ]) : UriInterface
Parameters
$params : array<string, scalar>|null = null
$scopes : array<string|int, mixed>|null = null
Return values
UriInterface

getName()

Returns the name of the provider/class

public final getName() : string
Tags
codeCoverageIgnore
Return values
string

getRequestAuthorization()

Authorizes the $request with the credentials from the given $token and returns a PSR-7 RequestInterface with all necessary headers and/or parameters set

public getRequestAuthorization(RequestInterface $request[, AccessToken|null $token = null ]) : RequestInterface
Parameters
$request : RequestInterface
$token : AccessToken|null = null
Tags
inheritDoc
see
OAuth1Provider::sendAccessTokenRequest()
Return values
RequestInterface

getUserRevokeURL()

Returns the link to the page where a user can revoke access tokens, or null if the value is not set

public final getUserRevokeURL() : string|null
Tags
codeCoverageIgnore
Return values
string|null

request()

Prepares an API request to $path with the given parameters, gets authorization, fires the request and returns a PSR-7 ResponseInterface with the corresponding API response

public request(string $path[, array<string|int, mixed>|null $params = null ][, string|null $method = null ][, StreamInterface|array<string|int, mixed>|string|null $body = null ][, array<string|int, mixed>|null $headers = null ][, string|null $protocolVersion = null ]) : ResponseInterface
Parameters
$path : string
$params : array<string|int, mixed>|null = null
$method : string|null = null
$body : StreamInterface|array<string|int, mixed>|string|null = null
$headers : array<string|int, mixed>|null = null
$protocolVersion : string|null = null
Tags
throws
UnauthorizedAccessException
Return values
ResponseInterface

sendRequest()

public final sendRequest(RequestInterface $request) : ResponseInterface
Parameters
$request : RequestInterface
Tags
throws
InvalidAccessTokenException
Return values
ResponseInterface

setLogger()

Sets an optional PSR-3 LoggerInterface

public final setLogger(LoggerInterface $logger) : static
Parameters
$logger : LoggerInterface
Tags
codeCoverageIgnore
Return values
static

setRequestFactory()

Sets an optional PSR-17 RequestFactoryInterface

public final setRequestFactory(RequestFactoryInterface $requestFactory) : static
Parameters
$requestFactory : RequestFactoryInterface
Tags
codeCoverageIgnore
Return values
static

setStreamFactory()

Sets an optional PSR-17 StreamFactoryInterface

public final setStreamFactory(StreamFactoryInterface $streamFactory) : static
Parameters
$streamFactory : StreamFactoryInterface
Tags
codeCoverageIgnore
Return values
static

setUriFactory()

Sets an optional PSR-17 UriFactoryInterface

public final setUriFactory(UriFactoryInterface $uriFactory) : static
Parameters
$uriFactory : UriFactoryInterface
Tags
codeCoverageIgnore
Return values
static

storeAccessToken()

Sets an access token in the current OAuthStorageInterface (shorthand/convenience)

public final storeAccessToken(AccessToken $token) : static
Parameters
$token : AccessToken
Tags
codeCoverageIgnore
Return values
static

addBasicAuthHeader()

Adds an "Authorization: Basic <base64(key:secret)>" header to the given request

protected addBasicAuthHeader(RequestInterface $request) : RequestInterface
Parameters
$request : RequestInterface
Return values
RequestInterface

cleanBodyParams()

Cleans an array of body parameters

protected cleanBodyParams(array<string, scalar|bool|null> $params) : array<string, string>
Parameters
$params : array<string, scalar|bool|null>
Return values
array<string, string>

cleanQueryParams()

Cleans an array of query parameters

protected cleanQueryParams(array<string, scalar|bool|null> $params) : array<string, string>
Parameters
$params : array<string, scalar|bool|null>
Return values
array<string, string>

construct()

A replacement constructor that you can call in extended classes, so that you don't have to implement the monstrous original `__construct()`

protected construct() : void

createAccessToken()

Creates an access token with the provider set to $this->name

protected final createAccessToken() : AccessToken
Tags
codeCoverageIgnore
Return values
AccessToken

getAccessTokenRequestHeaderParams()

Prepares the header params for the access token request

protected getAccessTokenRequestHeaderParams(AccessToken $requestToken, string $verifier) : array<string, scalar>
Parameters
$requestToken : AccessToken
$verifier : string
Return values
array<string, scalar>

getMeResponseData()

fetches the provider's "me" endpoint and returns the JSON data as an array

protected final getMeResponseData(string $endpoint[, array<string, scalar|bool|null>|null $params = null ]) : array<int|string, mixed>
Parameters
$endpoint : string
$params : array<string, scalar|bool|null>|null = null
Tags
see
UserInfo::me()
see
OAuthProvider::sendMeRequest()
see
OAuthProvider::handleMeResponseError()
throws
ProviderException
Return values
array<int|string, mixed>

getRequestHeaders()

Prepare request headers

protected final getRequestHeaders([array<string, string>|null $headers = null ]) : array<string, string>
Parameters
$headers : array<string, string>|null = null
Return values
array<string, string>

getRequestTarget()

Determine the request target from the given URI (path segment or URL) with respect to $apiURL, anything except host and path will be ignored, scheme will always be set to "https".

protected getRequestTarget(string $uri) : string

Throws if the host of a given URL does not match the host of $apiURL.

Parameters
$uri : string
Tags
see
OAuthInterface::request()
throws
ProviderException
Return values
string

getRequestURL()

Prepares the request URL

protected final getRequestURL(string $path[, array<string, scalar|bool|null>|null $params = null ]) : string
Parameters
$path : string
$params : array<string, scalar|bool|null>|null = null
Return values
string

getSignature()

Generates a request signature

protected getSignature(UriInterface|string $url, array<string, scalar> $params, string $method[, string|null $accessTokenSecret = null ]) : string
Parameters
$url : UriInterface|string
$params : array<string, scalar>
$method : string
$accessTokenSecret : string|null = null
Tags
link
https://datatracker.ietf.org/doc/html/rfc5849#section-3.4
see
OAuth1Provider::getRequestTokenRequestParams()
see
OAuth1Provider::getRequestAuthorization()
throws
ProviderException
Return values
string

handleMeResponseError()

handles errors for the `me()` endpoints - one horrible block of code to catch them all

protected final handleMeResponseError(ResponseInterface $response) : void

we could simply throw a ProviderException and be done with it, but we're nice and try to provide a message too

Parameters
$response : ResponseInterface
Tags
throws
ProviderException|UnauthorizedAccessException

parseTokenResponse()

Parses the response from a request to the token endpoint

protected parseTokenResponse(ResponseInterface $response[, bool|null $checkCallbackConfirmed = null ]) : AccessToken

Note: "oauth_callback_confirmed" is only sent in the request token response

Parameters
$response : ResponseInterface
$checkCallbackConfirmed : bool|null = null
Tags
link
https://datatracker.ietf.org/doc/html/rfc5849#section-2.1
link
https://datatracker.ietf.org/doc/html/rfc5849#section-2.3
see
OAuth1Provider::getAuthorizationURL()
see
OAuth1Provider::getAccessToken()
throws
ProviderException
Return values
AccessToken

sendAccessTokenRequest()

Sends the access token request

protected sendAccessTokenRequest(array<string, scalar> $headerParams) : ResponseInterface
Parameters
$headerParams : array<string, scalar>
Tags
see
OAuth1Provider::getAccessToken()
Return values
ResponseInterface

sendMeRequest()

prepares and sends the request to the provider's "me" endpoint and returns a ResponseInterface

protected sendMeRequest(string $endpoint[, array<string, scalar|bool|null>|null $params = null ]) : ResponseInterface
Parameters
$endpoint : string
$params : array<string, scalar|bool|null>|null = null
Return values
ResponseInterface

setAuthorizationHeader()

Adds the "Authorization" header to the given `RequestInterface` using the given array or parameters

protected setAuthorizationHeader(RequestInterface $request, array<string, scalar> $params) : RequestInterface
Parameters
$request : RequestInterface
$params : array<string, scalar>
Return values
RequestInterface

setRequestBody()

Prepares the request body and sets it in the given RequestInterface, along with a Content-Length header

protected final setRequestBody(StreamInterface|array<string, scalar|bool|null>|string $body, RequestInterface $request) : RequestInterface
Parameters
$body : StreamInterface|array<string, scalar|bool|null>|string
$request : RequestInterface
Tags
throws
ProviderException
Return values
RequestInterface

        
On this page

Search results