Can you use Google OAuth to search through users email? - php

I'm trying to create an application that uses Google OAuth for login, and then scans through the users email to see the last time they emailing certain people.
So the user logs in with Google OAuth, and then inputs johndoe#gmail.com --> I want to be able to search through their gmail to tell them the last time they spoke.
I can get "feeds" of their inbox, and other folders, but I can't find a way to query for an email.

Yes you can access a user's mail with OAuth and the IMAP protocol. There is specifications on how to use the OAuth and IMAP combination on developers.google.com, check the links from here: https://developers.google.com/google-apps/gmail/oauth_overview
PHP has good support for the IMAP protocol: http://php.net/manual/en/book.imap.php
You can use imap_search() in PHP for searching for messages with IMAP: http://www.php.net/manual/en/function.imap-search.php
Edit: Sorry, the PHP IMAP support does not work with OAuth. You should use the Zend_Mail_Protocol_Imap, which has the functionality to authorize with an IMAP server using OAuth. Using the method requestAndResponse, it is possible to make an IMAP SEARCH request.

Related

Google Secure Apps

I've been using a PHP script to access Google's SMTP and IMAP so that emails sent from the script page are copied to the client's Gmail sent items. However Google has now locked down and locked out "insecure apps" which also seems to lock out my script, no matter which settings I change in Gsuite or the gmail account. How would I make it a "secure app" given that the usual app password approach seems inapplicable, since the device is a web server?
Securing your App would consist on using the more secure OAuth2 protocol to make requests to the Gmail API or authenticate to the SMTP or IMAP.
Using the Gmail API is more user friendly and for your use case I think it's more indicated. You can start building a Gmail App using these tutorials.
Read these articles to know more about OAuth on Gmail Apps:
IMAP/SMTP
Google APIs

Authenticate specific gmail account Google API in PHP

I receive confirmation from users in my gmail account. I want to read them with a server side php script to display confirmation on my website. I got OAuth 2.0 client IDs and a service key from Google APis. How do I use these keys with the specific gmail account to get the emails? I cannot find any simple documentation.
You can not use a service account to access a normal users Gmail account. This is because there is no way to preauthorize it.
What you need to do is have the users authenticate your application using Oauth2 and get a refresh token for each user. Then you will be able to use the refresh token in your server sided script to request a new access token which you can use to read there gmails. The Google PHP client library team has created some examples for using their library which might help you. Google-api-php-client
Side note: If the users you are speaking of are part of a Google domains account then you can do it by giving service account permissions to access the users emails.

Logging into Office365 email using PHP

I have an application which I would like to integrate with my company's Office365 email through a single sign on.
Here is how I was thinking of doing it:
My application can take the email address and password (or username) which users have logged into it and pass it out to a web service (in this case a PHP page).
The PHP page takes the username and password and users them to sign into Office365 email.
The user is redirected to the email page.
We are using Office365 with a local Azure tenancy and local AD.
I have used this same methodology to integrate with Open SSO, however, I can not find any information in how to authenticate to Office365 pragmatically using PHP.
Can anyone advise how this is done / where I can look?
Thanks,
-Max
Take a look at this other post that should help you out:
Using PHP and LDAP to connect to Microsoft Office 365
--- Bob ---
I appear to be closer to the answer. Take a look at my question here to view the code - Sending custom HTTP request with PHP
There is also a blog post by MSDN which will provide you with more information here - http://blogs.msdn.com/b/exchangedev/archive/2014/03/25/using-oauth2-to-access-calendar-contact-and-mail-api-in-exchange-online-in-office-365.aspx

downloading gmail emails

I need to download Gmail emails using php api. there APIs for google. i do not exactly which api to use. i have web application. i have registered my application on google, oauth2.0. at this url Google Api console. i have downloaded this php API
I which there are many services. but not gmail. I do not want to use accessing emails using username and password API. i want to access using the token. which is permanent access token.
Google support OAuth authentication for IMAP. Use that.

Can I get my Gmail chats through PHP/Curl?

Since Gmail chat is unavailable through IMAP I have been trying to find a way to access them through curl. I know that you can log in to Gmail and read your emails using PHP and curl, but I have been unable to find a way to get just my chats. Is there a way for me to access them this way?
This works for google voice. Perhaps it'll work for google chat/talk as well.
https://github.com/aaronpk/Google-Voice-PHP-API

Categories