Button on site
For simple work with oAuth for clients, you can install a special button on site. When the button is clicked by the user, a modal window will open to choose the account and authorization of the application in it, after confirming the user will be redirected to the Redirect URl with Get-parameters. We explained it more in the ‘Example by steps’ guide.
To install a button on site you need to place several strings of the JS code in the place where you want this button to be shown. Button accepts parameters that are explained below
<script class="amocrm_oauth" charset="utf-8" data-client-id="xxxx" data-title="Button" data-compact="false" data-class-name="className" data-color="default" data-state="state" data-error-callback="functionName" data-mode="popup" src="https://www.amocrm.com/auth/button.min.js" ></script>
|data-title||The text, that will be shown to the user on the button (By default it will be “Log in with amoCRM”)|
|data-compact||If sent as true the text on the button won’t be shown, only an amoCRM logo will be shown|
|data-class-name||Class, that will be used for the button element on the page|
|data-color||Colour of the button
|data-state||Parameter of the status, that will be sent to the modal window|
|data-error-callback||Name of the function that should be on a global scope. Function will be requested, if the user declines giving permissions to the application. On enter function will receive an object with keys client_id (integration id) and error (code of the error). At the moment there is only one code of the error – access_denied, if the user declined to grant access.|
|data-mode||Parameters that can be used: popup и post_message.
For popup, the opened window will be closed, and a redirect to Redirect URl will be done in the main window, from which the modal window was opened.
For post_message redirect will be done in the window that was opened, after processing the code of authorization you will need to close the window. Also you can indicate information about the status of the action in the main window with the help of postMessage.
To use a button without the mechanism of the opening window or to change it we make its sources available by reference.