A
A
Anastasia2021-06-23 12:02:40
PHP
Anastasia, 2021-06-23 12:02:40

How to get Yandex oauth token in php?

It seems like they have instructions, but still have questions. Ideally, I would like to receive some kind of instruction from the category of "just do it like this."

I make a curl request like this:

$ch = curl_init("https://oauth.yandex.ru/authorize?response_type=token&client_id=863...09b&login_hint=nastya97core&force_confirm=no");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($ch);
curl_close($ch);
p($res);


and I get this message back:
Found. Redirecting to https://passport.yandex.ru/auth?retpath=https%3A%2F%2Foauth.yandex.ru%2Fauthorize%3Fresponse....

and if I copy this link and follow it, then Yandex prompts me to log in, and then it gives me a token in the URL, which comes after # and of course I can’t get it in php through $_SERVER. Tell me, without this "authorization" can I somehow get access? And how to catch this token, which is after #?

It feels like it’s easier just once a year (the token lives for a year) to do authorizations “manually”, receive tokens and change them in the code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-06-23
@sslion

OAuth Libraries for PHP choose any...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question