JavaScript is required to use Bungie.net

Group Avatar

BungieNetPlatform

"Updates, discussions, and documentation of the BungieNetPlatform API."

Request Join
originally posted in:BungieNetPlatform
8/19/2015 8:20:08 PM
1

Front end developer could use some help with cookies/not having to authenticate user on every page refresh

So coincidentally I'm a different front end dev with a different problem to the other recent post I can see on here at the moment. To learn some back end stuff I settled on creating a simple inventory management web app, I probably won't even share it with anyone, it's basically just for learning purposes. Anyway, I decided on using Laravel and [url=https://github.com/dazarobbo/BungieNetPlatform]dazarobbo's own php library[/url] and started playing around getting my user information which was all going great until suddenly my IP seemed to be unable to access the PSN login service, I realised that I was re-logging in/authenticating myself on every page refresh, so I assume that I'd made too many requests and they'd blocked me for a bit. So I guess I should avoid this by using cookies somehow? I can see that in the [url=https://github.com/dazarobbo/BungieNetPlatform/blob/master/src/PsnUser.php]PsnUser->Authenticate()[/url] function it is setting a cookiejar with guzzle, but I can't work out how to actually use these cookies and get it to just authenticate the user once and have it authenticated for the rest of the session. This is the only code I'm using, just to test for now: [quote]Route::get('/', function () { $apiKey = 'APIKEY'; $platform = new BungieNetPlatform\Platform($apiKey); $platform->setUser(new BungieNetPlatform\PsnUser('USERNAME', 'PASSWORD')); $platform->authenticateUser(); $platform->setUserContext(true); var_dump($platform->getUser()); exit; });[/quote] Apologies if this is a stupid question, but any help anyone can give me would be great.

Posting in language:

 

Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

View Entire Topic
  • When I wrote the library I didn't really intend for it to be used in that way because I don't consider it safe to be handling other users' details, including cookies. Regardless, PsnUser inherits from [url=https://github.com/dazarobbo/BungieNetPlatform/blob/master/src/PlatformUser.php]PlatformUser[/url], so you can use all the methods defined there. The one you will probably want to make use of is [url=https://github.com/dazarobbo/BungieNetPlatform/blob/master/src/PlatformUser.php#L72]getCookieJar[/url]. You'll need to serialise it (or just the cookies you're interested in) then store the result in some persistent area ($_SESSION, disk, etc...). Later when you need the cookies again, do the reverse - read the result from where it's stored and add them to the CookieJar.

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

    5 Replies
    You are not allowed to view this content.
    ;
    preload icon
    preload icon
    preload icon