Giter Club home page Giter Club logo

Comments (2)

milo avatar milo commented on August 23, 2024

It is because the old token is still in session. I'm solving it in application, catching the Milo\Github\UnauthorizedException and forcing new token. It looks like:

try {
    $api->decode(...);
} catch (UnauthorizedException $e) {
    Location("....?force=1");
    die();
}
# Force new OAuth token
if (isset($_GET['force'])) {
    $login->dropToken();
}

# Token obtaining
if ($login->hasToken()) {
    $token = $login->getToken();
} else {
    if (isset($_GET['back'])) {
        $token = $login->obtainToken($_GET['code'], $_GET['state']);
        header("Location: $appUrl");  # drop the 'code' and 'state' from URL
        die();
    } else {
        # Performs redirect to Github page
        $login->askPermissions("$appUrl?back=1");
    }
}

There is no automatic reaction, because it depends on application, how it wants to behave.

The way how to solve it automatically is to register own onResponse() callback like:

$api = new Github\Api;
$api->setToken($token);
$api->getClient()->onResponse(function (Milo\Github\Http\Response $response) use ($appUrl) {
    if ($response->isCode($response::S401_UNAUTHORIZED)) {
        header("Location: $appUrl?force=1");
        die();
    }
});

from github-api.

TheZoker avatar TheZoker commented on August 23, 2024

Works perfectly, thank you!

from github-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.