keyring
keyring copied to clipboard
Support for Write/Modifications methods in Gmail Service.
In the Gmail service, currently, we have scopes that support read-only methods like getting and listing.
const SCOPE = 'https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/userinfo.profile';
We have to add scopes like https://www.googleapis.com/auth/gmail.modify
that will enable Keyring to perform more operations.
It's super easy to make your own Gmail service. Take a look at Extending a Core Service in the docs.
You just create a new class (I called mine Keyring_Service_GoogleMailModify
), have it extend the Keyring_Service_GoogleMail
class and set the SCOPE
variable to whatever scopes you need.
There's some extra work to load and register the service but this Facebook Importer plugin does a pretty job as an example.
Thanks, @markbiek for the reply.
I got your point to extend Keyring_Service_GoogleMail but currently I am fetching Keyring_Service_GoogleMail as
$service = Keyring::get_service_by_name( 'google-mail' );
Extending Keyring_Service_GoogleMailModify would get trickier using $service. Thoughts?
@ashishgoyal247 The issue is that you can't perform write operations using the google-mail
service that comes with the plugin. You have to extend it and create your own.
@ashishgoyal247 You shouldn't need to create a new service to modify the scope. There might be something more granular (there are all kinds of filters and actions in Keyring) but you could use the service's _request_token_params
filter in order to adjust the scope. In this case I think it would be keyring_google-mail_request_token_params
I solved this by adding it into my own plugin main php file (not the keyring) this:
function add_scopes() {
return 'https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/userinfo.profile';
}
add_filter( 'keyring_google-mail_request_scope', 'add_scopes' );