keyring icon indicating copy to clipboard operation
keyring copied to clipboard

Support for Write/Modifications methods in Gmail Service.

Open ashishgoyal247 opened this issue 3 years ago • 5 comments

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.

ashishgoyal247 avatar Dec 25 '21 15:12 ashishgoyal247

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.

markbiek avatar Jan 12 '22 18:01 markbiek

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 avatar Jan 22 '22 06:01 ashishgoyal247

@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.

markbiek avatar Jan 22 '22 13:01 markbiek

@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

pablinos avatar Jan 24 '22 18:01 pablinos

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' );

radixs avatar May 31 '22 15:05 radixs