API Client
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
OneCRM\APIClient\AuthorizationFlow Class Reference

Public Member Functions

 __construct ($url, array $options=[])
 
 init ($grant, $auto_redirect=false)
 
 finalize (array $response=null)
 
 refreshToken ($refreshToken)
 

Protected Member Functions

 initAuthCode ($auto_redirect)
 
 validateResponseState ($response)
 
 finalAuthCode ($response)
 
 initResourceOwner ()
 
 initClientCredentials ()
 

Protected Attributes

 $url
 
 $options
 

Detailed Description

Implementation of OAUth2 flow

Constructor & Destructor Documentation

OneCRM\APIClient\AuthorizationFlow::__construct (   $url,
array  $options = [] 
)

Constructor.

Flow parameters passed in $options depend on authorization flow used:

  • client_id: API client ID. Required. Can be omited if ONECRM_CLIENT_ID environment variable is set.
  • client_secret: API client secret. Required. Can be omited if ONECRM_CLIENT_SECRET environment variable is set.
  • redirect_uri: Redirect URI. Required for Authorization Code flow. Can be omited if ONECRM_REDIRECT_URI environment variable is set.
  • username: 1CRM user name. Required for Resource Owner Password Credentials flow. Can be omited if ONECRM_USERNAME environment variable is set.
  • password: 1CRM user password. Required for Resource Owner Password Credentials flow. Can be omited if ONECRM_PASSWORD environment variable is set.
  • scope: Authorization request scope. Optional, defaults to profile
  • owner_type: user or contact. Default value is user
  • state: CSRF token. Optional
Parameters
$urlURL of API entry point, including api.php, ex. https://demo.1crmcloud.com/api.php
$optionsParams used by OAuth2 flow

Member Function Documentation

OneCRM\APIClient\AuthorizationFlow::finalize ( array  $response = null)

Finalizes Oauth2 Authorization Code Grant flow

This method must be called when user returns to redirect_url after granting access to the application.

Parameters
$responseNormally, this can be omited to use parameters passed by 1CRM OAuth server via query string.
Returns
OAuth2 access token
Exceptions
Error
OneCRM\APIClient\AuthorizationFlow::init (   $grant,
  $auto_redirect = false 
)

Starts OAuth2 flow.

Use this method to start authorization flow and obtain OAuth2 access token.

Valid values for $grant parameters are:

  • authorization_code: starts Authorization Code Grant flow
  • password: obtains an access token using Resource Owner Password Credentials Grant flow
  • client_credentials: obtains an access token using Client Credentials Grant flow

When password or client_credentials are used, this method returns an access token directly.

When authorization_code is used, this method returns an URI the user must visit to complete the authorization flow. Additionally, you can pass true in $auto_redirect to automatically send Location: header for redirect.

Exceptions
Error
OneCRM\APIClient\AuthorizationFlow::refreshToken (   $refreshToken)

Refreshes expired access token

Parameters
$refreshTokenRefresh token
Returns
New access token
Exceptions
Error

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