php - Guzzle 6: Two-legged OAuth1 Authorisation -
i using guzzle 6 , oauth subscriber machine-to-machine communcation, interfacing api base uri https://foo.bar ofwhich vendor provides following parameter instructiond:
- consumer key
- consumer secret
- request token url: https://foo.bar/oauth/request
- authorize url: https://foo.bar/oauth/authorize
- access token url: https://foo.bar/oauth/access
following the oauth bible, imply two-legged oauth required, wish bypass manual authorisation redirection, though unsure how how/where to-set request-token url , access token url @ client level.
i have setup simple client, using consumer-key , secret, allows partial api access
$stack = handlerstack::create(); $middleware = new oauth1([ 'consumer_key' => $params['consumerkey'], 'consumer_secret' => $params['consumersecret'], 'token_secret' => false, ]); $stack->push($middleware); $client=new client([ 'base_uri' => $params['baseuri'], 'handler' => $stack, 'auth' => 'oauth' ]); //leg #1: obtain application request token $requesttokenresponse = $client->post('/oauth/request')->getbody()->getcontents(); /* requesttokenresponse contains in single string variable value: *'oauth_token=4plbxbl9um9j6in7xldy5dydwjlrisq5qmqi43jaxaq& * oauth_callback_confirmed=true& * oauth_token_secret=jqcc51ja3q2yklv2xyphuromhghiwwjgcx%40hxvo3josbkywkvr' */ $requesttokenparams = []; foreach (explode('&',$requesttokenresponse) $querystring) { $query = explode('=', $querystring); $requesttokenparams[$query[0]] = $query[1]; } //leg #2 starts here //dynamically add middleware params (setting token , token_secret?) //obtain access token after middleware update $accesstokenresponse = $client->post('/oauth/access')->getbody()->getcontents();
i'm not sure how advance now:
it seem next post requires setting token , token_secret, requiring me modify middleware parameters before next call, doesn't seem work and/or pushing handler-stack manually..
please help, in advance
Comments
Post a Comment