Code Monkey home page Code Monkey logo

Comments (4)

kamermans avatar kamermans commented on June 15, 2024

Hi @ammonkc, sorry about the slow response! You're correct, there is no grant_type for setting the token manually, although you can set it via OAuth2Middleware::setAccessToken() or OAuth2Subscriber::setAccessToken() (it's inherited from OAuth2Handler::setAccessToken()). For example, if you are using Guzzle 6, you could do this:

// Mock reauth client since it's required for instantiation
$reauth_client = new Client(['base_uri' => 'http://localhost']);
$reauth_config = [
    "client_id" => "none",
    "client_secret" => "none"
];
$grant_type = new ClientCredentials($reauth_client, $reauth_config);
$oauth = new OAuth2Middleware($grant_type);

// Set access token manually
$oauth->setAccessToken([
    'access_token' => 'abcdefghijklmnop',
]);

from guzzle-oauth2-subscriber.

kamermans avatar kamermans commented on June 15, 2024

I was kind of annoyed that the only way to handle this is to mock a grant type that you don't want to use, so I added a new NullGrantType adapter to make it a little more clean, and I've documented the process for using a manual access token: https://github.com/kamermans/guzzle-oauth2-subscriber#manually-setting-an-access-token

from guzzle-oauth2-subscriber.

arderyp avatar arderyp commented on June 15, 2024

@kamermans I know this is old but figured it was better to ask here rather than open a new issue

I am using your new NullGrantType following the exact documentation but getting "No access token is present and there is no way to obtain one with NullGrantType", but I am indeed calling setAccessToken(['access_token' => 'abcdefg'])

Any thoughts?

from guzzle-oauth2-subscriber.

arderyp avatar arderyp commented on June 15, 2024

Nevermind, I think the issue was with a stale/invalid token. may be helpful for the system to throw a more meaningful error if the token is bad versus not being present.

from guzzle-oauth2-subscriber.

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.