Closed m-vdv closed 9 years ago
@webslash Just wait a bit. Huge update is coming with way better handling of OAuth. Also, can you check the redirect url you give to the outorize method?
@megawubs I have urn:ietf:wg:oauth:2.0:oob as the redirect uri. (Since I'm developing on localhost). I read now in the API docs that urn:ietf:wg:oauth:2.0:oob should be used for the PIN authentication. I'm lost what to use for local development then?
@webslash Doe you have a local hostname for the dev machine? You can use that as a redirect-URI. When your.local hostname is trakt-dev.app
and your route that catches the redirect from Trakt is /trakt/auth
you can register the redirect url as 'http://trakt-dev.app/trakt/auth' and catch the code with $_GET['code'];
Looked into setting up a virtual host and got it working! Thanks!
@webslash Happy to help!
@webslash Look at the TraktAccessToken class. The code you get after the redirect is not the access token. The code is for retrieving the access token
@webslash can you take a look at the develop branch and let me know what you think about the new setup?
@megawubs Just tried the new develop branch.
I got the OAuth more or less working. Users are send to trakt.tv where they can Authorize my app. Then they're send back with a ?code= which I then use to request a token. Then I receive the Token but I'm a bit lost on how to save this? Do I write this to a cookie or how should this be handled?
Anyway the new request scheme is a lot easier to use then before, so I would definitely suggest continuing development this way!
Thanks for all the help and work ;)
PS: the develop branch readme file has some error in it. For example: In your composer.json file add:"wubs/trakt": "dev-master" should be "wubs/trakt": "dev-develop" for now. Also $trakt = new $trakt($auth); should be $trakt = new Trakt($auth);
@webslash You could save the oauth info in a database, so you can recreate the access token when the user needs it.
Thanks for the readme errors, will fix them later.
@megawubs Just noticed Wubs\Trakt\Provider\TraktProvider in your readme should be Wubs\Trakt\Auth\TraktProvider ;)
Also the readme speaks of TraktAccessToken::ceate to re-create the AccessToken but that doesn't seem to exist?
I'm really struggling with the Token part. Would be helpful is you could explain some more how to exactly handle this in production.
After I use $token = $auth->token($_GET['code']); I get an array with accessToken, expires, and refreshToken values.
I'm a bit lost what to do with it next.
All help welcome! :)
@megawubs Is it possible to get the API response directly inside an Array instead of a Collection?
@webslash You can do $response->toArray()
@megawubs But, most of the time, a Collection can just be used as an array
Thanks ->toArray() does exactly what I wanted :)
@megawubs Still trying to figure out the token part.. The develop docs says
"With the values you can re-create the AccessToken when you need it by using the TraktAccessToken::ceate() method and pass the required parameters $token, $type and$expires"
But the the TraktAccessToken::ceate() method doesn't exist.. :/
@megawubs
TraktAccessToken is indeed missing from the develop branch.. I've used the master branch file and edited it a bit, it's working now :)
<?php
namespace Wubs\Trakt\Token;
use League\OAuth2\Client\Token\AccessToken;
class TraktAccessToken
{
public static function create($token, $expires, $refresh)
{
return new AccessToken(
[
"access_token" => $token,
"expires_in" => $expires,
"refresh_token" => $refresh,
]
);
}
}
You should use \Wubs\Trakt\Auth\Token::create($token, $type, $expires);
I forgot to change the classname in the readme. Is fixed now in 08312daa626f65fde30c2116f440a38d8bb130e2
Thanks for the update! You got a tiny typo: Token::ceate() should be Token::create()
It's working, but I have to send all vars to the create function ($token, $type, $expires, $refresh, $scope) for it to work though. Not sure what the $type and $scope should be, so I send null and that works.
Updated the docs to reflect the need for $refresh
and $scope
.
Thank you for being so patient and helpful!
Hi @megawubs
I'm trying to get your API wrapper to work smoothly, currently setting up the OAuth stuff on my local machine. When I call the authorize function it opens trakt.tv and shows a PIN authentication page. I read in the docs about this new feature, but it's not what I want to use. Why isn't the OAuth working as it should?
Thanks