Set up the sdk-suggest.js script for the authorization page
Enable one of the script versions on the user authorization page:
<head>
<script src="https://yastatic.net/s3/passport-sdk/autofill/v1/sdk-suggest-with-polyfills-latest.js"></script>
</head>
See also:
<head>
<script src="https://yastatic.net/s3/passport-sdk/autofill/v1/sdk-suggest-latest.js"></script>
</head>
Syntax and parameters
YaAuthSuggest.init(oauthQueryParams, tokenPageOrigin, [suggestParams])
Warning
The suggestParams group of parameters is only applicable to the button. When using the widget, don't specify those parameters.
A call example:
YaAuthSuggest.init(
{
client_id: 'c46f0c53093440c39f12eff95a9f2f93',
response_type: 'token',
redirect_uri: 'https://examplesite.com/suggest/token'
},
'https://examplesite.com'
)
.then(({
handler
}) => handler())
.then(data => console.log('Message with a token', data))
.catch(error => console.log('Error handling', error));
YaAuthSuggest.init(
{
client_id: 'c46f0c53093440c39f12eff95a9f2f93',
response_type: 'token',
redirect_uri: 'https://examplesite.com/suggest/token'
},
'https://examplesite.com',{
view: 'button',
parentId: 'container',
buttonView: 'main',
buttonTheme: 'light',
buttonSize: 'm',
buttonBorderRadius: 0
}
)
.then(({
handler
}) => handler())
.then(data => console.log('Message with a token', data))
.catch(error => console.log('Error handling', error));
See also Example of usage on an HTML page
Parameter descriptions:
|
Parameter |
Required |
Type |
Description |
| oauthQueryParams contains query parameters that are used when opening the OAuth authorization page (see the full list of query parameters). | |||
|
|
Yes |
|
The OAuth app ID received after registration. |
|
|
Yes |
|
The request type. |
|
|
No |
|
The URL of the callback page that receives the token. Must match the address you entered in the Redirect URI field for the OAuth app with this |
tokenPageOrigin is a parameter that enables the authorization page to communicate with the callback page via postMessage. | |||
|
Only the parameter value is specified. |
Yes |
|
"Origin" of the callback page that receives the token. This parameter can't be unspecified or contain the |
| suggestParams contains parameters that determine the button's appearance. They're only specified when the authorization component is a button. They don't apply to a widget. There is a button generator to help you tweak the parameter values. | |||
|
|
Yes |
|
Parameter for displaying the |
|
|
No |
|
The |
|
|
No |
|
The button type. By default —
|
|
|
No |
|
Button theme. To avoid the button blending into the background, change this parameter when your website page's or app's theme changes. By default —
|
|
|
No |
|
The button size that determines its height, width, and switching to the minimized or maximized appearances. By default:
|
|
|
No |
|
The button's border radius (the value of the |
|
|
No |
|
The language of the logo on the button. The default value is
|
|
|
No |
|
The background color of the icon button. Can be specified in any format supported by CSS. This parameter is only applicable to the |
|
|
No |
|
The background color of the icon button on hover. Can be specified in any format supported by CSS. This parameter is only applicable to the |
|
|
No |
|
The border color of the icon button. Can be specified in any format supported by CSS. This parameter is only applicable to the |
|
|
No |
|
The border color of the icon button on hover. Can be specified in any format supported by CSS. This parameter is only applicable to the |
|
|
No |
|
The border width of the icon button. This parameter is only applicable to the |
Button generator
Select parameter values that suit your needs. The generator will render the button and produce the code with the same parameters.
Copy the generated code and paste it into the page. In the code, substitute:
-
oauthQueryParamswith the strings below.{ client_id: 'c46f0c53093440c39f12eff95a9f2f93', response_type: 'token', redirect_uri: 'https://examplesite.com/suggest/token' }Use the following parameter values in these strings:
- For
client_id— the ID of the OAuth app registered in Step 1. - For
redirect_uri— the URL of the callback page you entered in the Redirect URI field for the OAuth app that has thisclient_id(if you don't specify any URL, the first value from the Redirect URI field will be used).
- For
-
tokenPageOriginwith the "origin" of the callback page that receives the token.
Return value
{
status: 'ok',
handler: handler,
}
{
status: 'error',
code: '...'
}
Response parameters:
|
Parameter |
Description |
|
|
Response status:
|
|
|
The function that returns a Promise as an iframe with the login button or widget when |
|
|
The error code when |
Example of usage on an HTML page
An instant login widget or a login button is added to the page:
- To add a login button, use the whole code below.
- To add a widget, use the code below after excluding the additional
suggestParamsparameters that determine the login button's appearance.
<!doctype html>
<html lang="ru">
<head>
<meta charSet="utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, shrink-to-fit=no, viewport-fit=cover'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<style>
html,
body {
background: #eee;
}
</style>
<script src="https://yastatic.net/s3/passport-sdk/autofill/v1/sdk-suggest-with-polyfills-latest.js"></script>
</head>
<body>
<script>
window.onload = function() {
window.YaAuthSuggest.init({
client_id: 'c46f0c53093440c39f12eff95a9f2f93',
response_type: 'token',
redirect_uri: 'https://examplesite.com/suggest/token'
},
'https://examplesite.com', {
view: 'button',
parentId: 'container',
buttonView: 'main',
buttonTheme: 'light',
buttonSize: 'm',
buttonBorderRadius: 0
}
)
.then(function(result) {
return result.handler()
})
.then(function(data) {
console.log('Message with a token: ', data);
document.body.innerHTML += `Message with a token: ${JSON.stringify(data)}`;
})
.catch(function(error) {
console.log('Something went wrong: , error);
document.body.innerHTML += `Something went wrong: ${JSON.stringify(error)}`;
});
};
</script>
</body>
</html>