Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster. https://www.postman.com/
1.To connect a site, get your site token - get token
2. Next, send users to links like:
https://api.clickauth.net/api/auth/[AUTH_TYPE]?domain=[DOMAIN]&redirect=[REDIRECT_URL]&token=[CLICK_LOGIN_TOKEN]
Example:
https://api.clickauth.net/api/auth/vk?domain=clickauth.net&redirect=https://clickauth.net/playground&token=40f9931e4a5fb8...
Parameter | Meaning |
---|---|
[AUTH_TYPE] | Social authorization network: vk, fb, ok, gp, mailru, yandex, linkedin |
[DOMAIN] | Your domain for which the token was received |
[REDIRECT_URL] | Link where the authorization handler is located |
[CLICK_LOGIN_TOKEN] | Public token issued by our service |
3.After the user logs in through the social network, he will follow the link passed in the [REDIRECT_URL]?token_auth=... parameter, where you should check if the authorization is correct. Namely received token on your side from the token_auth parameter.
https://api.clickauth.net/api/usereq?token=[TOKEN_AUTH]
4. Get the user data from the userreq request, register it in the system, and authorize.
The login.html page has the code:
<div class="widgetlogin">
<p>Authorization via Vkontakte</p>
<!-- Parameters are important in the link: token & domain & redirect -->
<a href="https://api.clickauth.net/api/auth/fb?domain=clickauth.net&redirect=https://clickauth.net/ru/playground/&token=40f9931e4a5fb888f4ce06f7a132f91b141b6ef926cc11cc1fe2d6ffe3e648afedb3afe7fdb6e00b6571a3d75f753eba348889b289b6bdcf6505225add">
Click to enter!
</a>
</div>
2) An example of processing after the user was redirected to the "redirect" page (php handler) for example: https://example.ru/callback.php
// PHP
function check_auth() {
$params = array(
/* Enter your {domain} to which the token was issued - http://clickauth.net/addsite */
'domain' => 'clickauth.net',
/* Get {token_auth} */
'token_auth' => $_REQUEST['token_auth']
);
/* Get authorization information */
$query = "https://api.clickauth.net/api/usereq?" . http_build_query($params, null, '&');
$json = @file_get_contents($query);
if(!empty($json)) {
$response = (array) json_decode($json,true);
/* если юзер существует */
if(isset($response['error']) && $response['error'] === false) {
echo($response['user']['id']); /* (numeric) Identifier clicklogin */
echo($response['user']['user_id']); /* (numeric) Identifier соц. сети */
echo($response['user']['email']); /* (string) Mail, usually there is always*/
echo($response['user']['first_name']); /* (string) Firstname, usually there is always*/
echo($response['user']['last_name']); /* (string) Lastname, usually there is always*/
echo($response['user']); /* Fully */
return (array) $response['user'];
}
}
return array();
}
$user = check_auth();
if(!empty($user)) {
var_dump($user);
}
else {
echo 'Authorization failed!';
}