samwilson / phpflickr

A PHP wrapper for the Flickr API, including OAuth.
https://packagist.org/packages/samwilson/phpflickr
GNU General Public License v2.0
39 stars 15 forks source link

Help with web-based authentication #66

Closed tacman closed 3 months ago

tacman commented 3 months ago

I'm confused about how to set up the web-based authentication. Here's are my two controllers:

    #[Route('/flickr_login', name: 'flickr_login')]
    public function login(FlickrService $flickr): Response
    {
        $storage = new Session();
// Create the access token from the strings you acquired before.
        $token = new StdOAuth1Token();
// Add the token to the storage.
        $storage->storeAccessToken('Flickr', $token);

        $perm = 'read';
        $url = $flickr->getAuthUrl($perm, $this->urlGenerator->generate('app_flickr', [], UrlGeneratorInterface::ABSOLUTE_URL));

        return $this->render('flickr/index.html.twig', [
            'url' => $url,
        ]);
    }

    #[Route('/flickr', name: 'app_flickr')]
    public function index(Request $request, FlickrService $flickr): Response
    {
        $accessToken = $flickr->retrieveAccessToken($request->get('oauth_verifier'), $request->get('oauth_token'));
        $userId = $this->flickrService->test()->login();
    }

The oauth returns to the url correctly:

https://127.0.0.1:8000/flickr?oauth_token=72157720919697445-b0acefd2b8ba684f&oauth_verifier=b2bb64f7852464fe

It fails on retrieveAccessToken:

Warning: Undefined array key "oauth_token"

image

Any help would be appreciated.

tacman commented 3 months ago

If useful, I could publish a demo repo. I'm working on the flickr-bundle I've mentioned elsewhere, it will make using this bundle even easier for Symfony developers.

tacman commented 3 months ago

I think the problem is related to refreshing the page during debugging, and the access token can only be used once before it expires.

When I back up and re-authorize, it works as expected.