Xwilarg/Discord-OAuth2-PHP

OAuth2 Page Just Refresh

piercegearhart opened this issue · 8 comments

Hello! I have setup this package on my website, and it successfully redirects me to the discord oauth2 page, but every time I click authorize it seems to refresh the page and it's the same. I see this is setup to callback to the redirect url instead of a callback URL, and I assume that instead of seeing I authorized already it's just taking me back to the authorize screen. What have I done wrong? Here is my code:
`$oauth2 = new OAuth2("882622674352873522", "[SECRET]", "https://netrx.piercegearhart.com/account/discord/redirect");

if ($oauth2->isRedirected() === false) {
    $oauth2->startRedirection(['identify', 'connections', 'email', 'guilds']);
} else {
    $ok = $oauth2->loadToken();
    if ($ok !== true) {
        $oauth2->startRedirection(['identify', 'connections', 'email', 'guilds']);
    } else {
        $answer = $oauth2->getUserInformation();
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            echo "Welcome " . $answer["username"] . "#" . $answer["discriminator"];
        }

        echo '<br/><br/>';
        $answer = $oauth2->getConnectionsInformation();
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            foreach ($answer as $a) {
                echo $a["type"] . ': ' . $a["name"] . '<br/>';
            }
        }
    }
}`

Thanks for your bug report, I'll investigate that and keep in touch with you when I'll have more information

On a side note, your message was containing your application secret, please regenerate it on the Discord Developer page to avoid any problem

Oh, thank you. I forgot about that lol. Thanks for the quick response!

I tried to reproduce your issue but I don't encounter any problem

My example is hosted on https://test.zirk.eu/ and made out of one page called index.php.
image
index.php contains the following:

<?php

require __DIR__ . '/vendor/autoload.php';

use Xwilarg\Discord\OAuth2;

$oauth2 = new OAuth2("808406108631728139", "my_token", "https://test.zirk.eu");

if ($oauth2->isRedirected() === false) {
    $oauth2->startRedirection(['identify', 'connections', 'email', 'guilds']);
} else {
    $ok = $oauth2->loadToken();
    if ($ok !== true) {
        $oauth2->startRedirection(['identify', 'connections', 'email', 'guilds']);
    } else {
        $answer = $oauth2->getUserInformation();
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            echo "Welcome " . $answer["username"] . "#" . $answer["discriminator"];
        }

        echo '<br/><br/>';
        $answer = $oauth2->getConnectionsInformation();
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            foreach ($answer as $a) {
                echo $a["type"] . ': ' . $a["name"] . '<br/>';
            }
        }
    }
}

As you can see, if you click on the URL you have the auth page which then redirect you to the same page, displaying the informations

Do you see any difference with that you currently have?

I don't see a difference, no. I copied the code you provided above and replaced mine with it, and changed the redirect URL, Client ID and Token to mine and tried again, same issue. I moved the code from /account/discord/redirect to just the index file of netrx.piercegearhart.com and it worked... so it appears the issue has something to do with it being in a directory like that or something of the such?

Could you maybe replace the two2 $oauth2->startRedirection by a print and tell me which one is causing the issue?
If it's the second one, try to do a var_dump of $ok and see if there is any information inside

I found the issue.. I changed the redirect URL to have .php at the end and it worked.. so an issue on my end. I have it setup in my .htaccess to remove .php from php files which worked on my localhost, but not when I moved it to my VPS. If I try to go to the page with .php it just doesnt load, which I guess was also causing and issue with this.

Ah, well that's good to know, feel free to tell me if you encounter any other issue

For sure, and thank you so much for the quick help, really means a lot.