Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Write/Modifications methods in Gmail Service. #100

Open
ashishgoyal247 opened this issue Dec 25, 2021 · 5 comments
Open

Support for Write/Modifications methods in Gmail Service. #100

ashishgoyal247 opened this issue Dec 25, 2021 · 5 comments

Comments

@ashishgoyal247
Copy link

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.

@markbiek
Copy link

markbiek commented Jan 12, 2022

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.

@ashishgoyal247
Copy link
Author

ashishgoyal247 commented Jan 22, 2022

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?

@markbiek
Copy link

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

@pablinos
Copy link
Collaborator

@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

@radixs
Copy link

radixs commented May 31, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants