lusitanian/oauth and Scopes

in php •  7 years ago 

I recently had a task come up where an existing system needed to allow its users to connect their YouTube account to their site account. Pretty simple task, really, when you get down to it.

  1. Use Oauth to allow YouTube to authenticate the connection
  2. Save said connection for later use
  3. ...

Yeah, no #3; easy peasy at first glance. But there was a complication.

  1. There were specific scopes needed (we needed permission to read their YouTube Comments)
  2. The site used an existing oauth library that, out of the box, didn't allow for all scopes we needed :(

For some reason (to be fair, I never did bother to ask the author the why of this...) but the library doesn't allow for the selection of the https://www.googleapis.com/auth/youtube.force-ssl Scope. And THAT scope is needed to read YouTube Comments, so little problem.

So, a Googlin' I went. To find fuck all about how to get around it. Which either meant I was an idiot and missing an obvious solution or I was the only person to ever have this issue with this library.

Jury's still out on the answer, but after 500 words of "where the fuck's he going with this", the solution was pretty simple.

  1. Create a Service object that extends the existing object
  2. Tell the library where to find the new object

The new service object

<?php
namespace Mithra62\Oauth\Services;

use OAuth\OAuth2\Service\Google AS GoogleService;

class Google extends GoogleService
{
    const SCOPE_YOUTUBE_HTTPS = 'https://www.googleapis.com/auth/youtube.force-ssl';
}

Tell the library where to find the new object

<?php
use OAuth\ServiceFactory;

$service = new ServiceFactory();
$service->registerService('Google62', '\Mithra62\Oauth\Services\Google');
//continue oauth setup...
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @mithra62! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Why you don't just use hybridauth? This library has already everything you need: https://github.com/hybridauth/hybridauth

My tip: Use version 2, version 3 is still in beta.

Congratulations @mithra62! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Do not miss the last post from @steemitboard:

Valentine challenge - Love is in the air!

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @mithra62! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Valentine's day challenge - Give a badge to your beloved!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!