TheCodingCompany/MastodonOAuthPHP

cant get acces token

Closed this issue · 5 comments

hello, i tried your, and i'm stuck in step

//Request the bearer token
$token_info = $t->getAccessToken(

here is the log with debug true:

<pre>Array
(
    [http] => Array
        (
            [method] => POST
            [header] => Content-Type: application/json; charset=utf-8
Accept: */*
            [content] => {"grant_type":"authorization_code","redirect_uri":"urn:ietf:wg:oauth:2.0:oob","client_id":"acd[...]4cf","client_secret":"7c9[...]6ea","code":"1c1abfcaec36db298f6fc0f96913c311e9cc73652031133ad4937e654d81112c"}
            [user_agent] => Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
            [timeout] => 30
            [protocol_version] => 1.1
        )

    [ssl] => Array
        (
            [verify_peer] =>
            [verify_host] =>
            [ciphers] => HIGH
        )

)
</pre>https://lavraievie.social/oauth/token<br/><pre>Array
(
    [type] => 2
    [message] => file_get_contents(https://lavraievie.social/oauth/token): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

    [file] => /usr/src/followBot/vendor/thecodingcompany/php-mastodon/theCodingCompany/HttpRequest.php
    [line] => 166
)

"code" is what i get from an url like 'https://lavraievie.social/oauth/authorize/f0d59a0623c' pn the previous step.

do you have any idea ?

Hi, your client_id and client secret are invalid or you token is already a bearer token? Did you login a user or ?

Hi,
How to check my client_id and my client secret ?
I just generate them randomly and used them in every previous request, is this wrong ?

I got the token on the frontend of my instance connected with my acoount.

I got the same error trying to login with email/password, so i guess it's a problem with client_id and client_secret .
I will check what i missed

You can't just generate them randomly. LOL. You either create a so called 'APP' or you authenticate a specific user. In your case you should follow the example on the main page. https://github.com/TheCodingCompany/MastodonOAuthPHP

Steps:

  1. Create an APP (this will return your 'client_id' and 'client_secret' with: $t->createApp("MyCoolAppName", "http://www.internet.com");
  2. Get the authorization url, with $t->getAuthUrl(); and redirect the user
  3. Exchange the authorization code for a bearer token with: $t->getAccessToken("7c47d0c636314a1dff21reryyy5edf91884856dc0f78148f848d475136");

Owh, is see, it was not obvious for me.
I will check that in ~7hours

thanks

ok, thanks, it works fine now ...