Link or unlink accounts
Account linking/unlinking requires a valid access token (from a previous Authentication or Registration). It is not possible to link one existing user record to another, so the only scenario that needs to be addressed is linking to a Social account.
For linking and unlinking, it will be necessary to first make an API call to the /entity operation to retrieve or to verify the current list of the user’s linked accounts.
$api_call= '/entity';
$params= array(
'access_token'=> $_SESSION['access_token'],
// attributes containing user's linked accounts
'attributes'=> '["profiles.domain", "profiles.identifier"]'
);
$curl= curl_init();
curl_setopt($curl,CURLOPT_URL,JANRAIN_CAPTURE_URL.$api_call);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($params));
$api_response= json_decode(curl_exec($curl));
curl_close($curl);
Account link
-
Authenticate with the social provider to retrieve the social login token. (See Social login configuration guides for instructions.)
-
Link the social account via the oauth/link_account_native call.
For example:
$api_call= '/oauth/link_account_native';
$params= array(
'client_id'=> JANRAIN_LOGIN_CLIENT_ID,
'flow'=> JANRAIN_FLOW_NAME,
'flow_version'=> JANRAIN_FLOW_VERSION,
'locale'=> 'en-US',
'redirect_uri'=> 'https://localhost',
// valid access token
'access_token'=> $_SESSION['access_token'],
// social login token obtained from previous step
'token'=> $_POST['token']
);
$curl= curl_init();
curl_setopt($curl,CURLOPT_URL,JANRAIN_CAPTURE_URL.$api_call);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($params));
$api_response= json_decode(curl_exec($curl));
curl_close($curl);
Response | Outcome / Next Step |
---|---|
Success (ok) | Account is linked. |
Social account already exists (unique_violation) | Provide a resolution path for this error. |
Account unlink
Unlink a social account via the /oauth/unlink_account_native call.
$api_call= '/oauth/unlink_account_native';
$params= array(
'client_id'=> JANRAIN_LOGIN_CLIENT_ID,
'flow'=> JANRAIN_FLOW_NAME,
'flow_version'=> JANRAIN_FLOW_VERSION,
'locale'=> 'en-US',
// valid access token
'access_token'=> $_SESSION['access_token'],
// identifier value from profiles.[profile].identifier schema attribute
'identifier_to_remove'=> $_POST['identifier']
);
$curl= curl_init();
curl_setopt($curl,CURLOPT_URL,JANRAIN_CAPTURE_URL.$api_call);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($params));
$api_response= json_decode(curl_exec($curl));
curl_close($curl);
Response | Outcome / Next Step |
---|---|
Success (ok) | Account is unlinked. |
Updated about 2 years ago