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.
- Use Oauth to allow YouTube to authenticate the connection
- Save said connection for later use
- ...
Yeah, no #3; easy peasy at first glance. But there was a complication.
- There were specific scopes needed (we needed permission to read their YouTube Comments)
- 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.
- Create a Service object that extends the existing object
- 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...