Using OAuth
The OAuth 2.0 Authorization Framework enables user to authorize your application to get user's information or access API methods otherwise not accessible by default client credentials.
OAuth 2 rely on separate standards for the access tokens. In Wallet API MAC access authentication is used - the same protocol that is available for client authentication.
Currently two grant types are available:
authorization code grant - used on web systems, recommended method
resource owner password credentials grant - used on mobile and desktop programs, only allowed for specific clients
Using authorization code grant
To use OAuth authorization code grant, client should follow these steps:- Redirect user to authentication endpoint with client_idparameter and redirection URI;
- 
        After user authenticates in the Paysera system, she is redirected
        to provided redirection URI together with parameter code;
- 
        Client makes API request to the token endpoint providing the codeparameter. Response containsaccess_tokenandmac_keyparameters;
- 
        Client makes API requests, using access_tokenandmac_keyinstead of default credentials for MAC authentication scheme.
Confirming transaction and redirecting to authentication
In case you want User to confirm transaction and immediately grant permissions to requested scopes, please use following endpoint.
Firstly User will be asked to confirm given transaction, if confirmation succeeds, User will be redirected to OAuth authentication endpoint.
https://www.paysera.com/frontend/transaction/confirm-with-oauth/:transaction_key
URI parameters:
- transaction_keyTransaction key. You can get one by creating transaction endpoint
Query parameters:
Same Query parameters are supported as in authentication endpoint.
Redirecting user to authentication endpoint
User must be redirected to the following URI, providing required parameters in query:
https://www.paysera.com/frontend/oauth
To control the default web page language, redirection can be made to the following URI:
https://www.paysera.com/frontend/locale/oauth
Where locale is one of the following:
en - for English language
lt - for Lithuanian language
ru - for Russian language
Together with URI some query parameters must be provided.
response_type
                code is supported
                client_id
                client_id parameter, provided with credentials for client
                redirect_uri
                scope
                state
                https://www.paysera.com/frontend/oauth?response_type=code&client_id=wkVd93h2uS&redirect_uri=http%3A%2F%2Flocalhost%2Fabc&state=iQZMRnQCtm
Redirection back to client's site
After user authorizes project, she will be redirected to the providedredirection_uri. code and state (if it was provided)
parameters will be sent together with the URI. For example:
HTTP/1.1 302 Found Location: http://localhost/abc?code=SplxlOBeZQQYbYS6WxSbIA&state=iQZMRnQCtmIn the case of canceling authorization request or some other error, user will be redirected to the
redirection_uri with these query parameters:
- 
        error- type of an error. One of:invalid_request,unauthorized_client,access_denied,unsupported_response_type,invalid_scope,server_error,temporarily_unavailable
- state- the same as was passed during redirect to authorization endpoint
HTTP/1.1 302 Found Location: http://localhost/abc?error=access_denied&state=iQZMRnQCtm
Requesting access token
Token endpoint:https://wallet.paysera.com/oauth/v1/tokenAfter confirming the
state parameter, you can request access token by providing code
parameter. POST request must be made to the token endpoint by adding the following parameters using the
application/x-www-form-urlencoded format in the HTTP request body:
- grant_type- always- authorization_code;
- code- the- codethat you have got when user was redirected back to your site;
- redirect_uri- exactly the same as was included in the authorization redirect.
POST /oauth/v1/token HTTP/1.1 Host: wallet.paysera.com Content-Type: application/x-www-form-urlencoded;charset=utf-8 User-Agent: Paysera WalletApi PHP library Authorization: MAC id="wkVd93h2uS", ts="1343811600", nonce="nQnNaSNyubfPErjRO55yaaEYo9YZfKHN", mac="ElTV7TYXQrZrBe0tL6PtqvH6EI15iBSd/JvAkpMoH64=", ext="body_hash=IftzxAtYliLQx46c2JAPidlHKqck0OXD7KmsHNnSptU%3D"
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=http%3A%2F%2Flocalhost%2FabcResponse contains new credentials to use for API calls, related to the current user and her wallet:
- access_token- value to use instead of- client_idin API calls;
- token_type- always- mac;
- expires_in- access token expiration timeout in seconds;
- mac_key- value to use instead of default- mac_keyin API calls;
- 
        mac_algorithm- algorithm to use when calculatingmac. Alwayshmac-sha-256;
- refresh_token- value to use for renewing expired token. This item is optional and can be missing.
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Cache-Control: no-store Pragma: no-cache
{
    "access_token": "SlAV32hkKG",
    "token_type": "mac",
    "expires_in": 3600,
    "mac_key": "adijq39jdlaska9asud",
    "mac_algorithm": "hmac-sha-256",
    "refresh_token": "0UnzbsnOLSkC7ftN"
}
Passing confirmed user information to ease registration
If your project has special privilege, you can provide already confirmed user information to ease registration process - user will not have to confirm his/her email or/and phone once again.
Request
POST https://wallet.paysera.com/rest/v1/contact-token
Request body structure
Request body must be encoded in JSON - same as in most other API requests. Confirmed contact will be valid for 15 minutes after creation.email
                phone provided
                phone
                email provided
                Response data structure
email
                phone
                status
                token
                expires_at
                Statuses
accessToken - optional; access token identifier, used as MAC id parameter. Can be omitted if request is made with the access token itself.
Example request
DELETE /oauth/v1/token?access_token=SlAV32hkKG HTTP/1.1 Host: wallet.paysera.com User-Agent: Paysera WalletApi PHP library Authorization: MAC id="wkVd93h2uS", ts="1343811600", nonce="nQnNaSNyubfPErjRO55yaaEYo9YZfKHN", mac="qtfqgX6EaE0nSHP9fN9ItmTNWqmr1Jkal7IOJbglOOE="
