How to find mail server type from email address? - oauth

How can I find from the user's email, e.g. someone#somecompany.com, whether it is using a google mail server, microsoft server or another server?
More details:
I need to look at the free/busy information in the user's calendar. In order to get permission and get Oauth token, I need to know which type of server is so I can connect to that Oauth server.

Related

Azure static web app - send email from the logged in user a week later. How to handle authentication?

I have an azure static web app set up with durable functions. I want the user to log in with their microsoft account, write a message and an email address, and that email will be sent a week later using the MS Graph Api.
I don't want to use Mail.Send application permissions as this lets the app send from anyone in the organisation. So I have Mail.Send delegated permissions.
After the user logs in, how can I send mail a week later, as the access token will have expired? Do I need to handle the refresh token manually or is there a built in way Azure Static Web Apps does this?
No built in way. You will have to manually refresh the token in your backend until you need to send the email out.

How to get userId from access token for Gmail OAuth2.0

What I'm trying to do
I'm trying to create a web app that would fetch emails from a user's Gmail. I understand that I would require authentication via Google OAuth 2.0.
What I'm trying to do is setting a watch() request on an inbox. Then, when the watched inbox gets an email, I want to get notified. I'm using Google's PubSub API.
What I've done
I followed the steps given in the Gmail OAuth documentation, but am confused as to how to store multiple access tokens for multiple users.
So when the user first logs in using their Gmail account, I generate a code which I exchange for an access token. Then I store this in a database. However, when I get notified about an email, I only receive from the API the user's email address. I would like to do some further API calls for this user. So now I would need to retrieve the token for the specific user. But...
The problem
... How do I store access tokens by email? I only have access to their token once they login/authorize. Is there any way of retrieving the email address from an access token? I could then store the access tokens as key-value pairs of <email address>-><access token>.
You can do a Users: getProfile-request immediataly as they log in for the first time, like so:
GET https://www.googleapis.com/gmail/v1/users/me/profile?access_token=<ACCESS_TOKEN_OF_THE_LOGGED_IN_USER>
Response:
{
"emailAddress": "example#gmail.com", // Here is the user's email address.
"messagesTotal": 6446,
"threadsTotal": 4495,
"historyId": "570232" // Here is the current historyId of his account.
}
Then, when you get a push request via watch(), you can use the historyId in the response above to see what has happened.

How to securely transfer to the server an email address that was authenticated on the browser?

I am able to use the "hello.js" library, which implements the oauth2 protocol on the client, to obtain the email address for a user authenticated via a third-party app (Google and Facebook).
Of course it would be possible to send the email address to the server over HTTPS, but how can I prevent the exchange from being spoofed? That is, how can the server be assured that the email address being received from the browser is the one that was authenticated via the third-party app?
Perhaps the email address is somewhere in the message sent to the "redirect_uri", which passes thru the server on the way to the client, but if so, I can't find it. It's not in the GET or POST parameters.
Andrew Dodson, the author of "hello.js", has been kind enough to answer this question for me on Gitter. He wrote:
The client side web app needs to send the token (find it after login
with hello('facebook').getAuthResponse().access_token) back to your
server. This token can be used anywhere to make an API request to the
third party.
So the browser doesn't send the actual email address to the server. Instead, it sends the token, and then the server uses the token to ask the third-party app for the email address associated with that token.

What are the end points to get the emailId using oauth for the google, yahoo, twitter service providers?

I am using google appengine java web application. I'm trying to put OpenId authentication withIn my project. I am using scribe to make this happen. I am able to get the Access Token from the google, yahoo, twitter Service Providers.
After getting the Access Token, I need to get the currently logged-in user email address. I'm using OAuth2.0 for google, OAuth1.0a for yahoo and twitter.
Any suggestions would be appreciated.
Google :
https://www.googleapis.com/oauth2/v3/userinfo?access_token={0}
Twitter :
Twitter does not expose an endpoint that provides the user's email address. Not even the profile endpoint. Below is an extract from the Twitter's FAQs page...
If you'd like a user's email address, you'll need to ask a user for it within the confines of your own application and service. The Twitter API does not provide the user's email address as part of the OAuth token negotiation process nor does it offer other means to obtain it.
Yahoo :
I don't think it exposes the user's email address either. Yet, the endpoint to retrieve the user's profile is...
http://social.yahooapis.com/v1/user/{guid}/profile
You can find more info here. http://developer.yahoo.com/social/rest_api_guide/extended-profile-resource.html

D2L email integration using web service. Get all messages in inbox for logged in user.

Am integrating D2L using Java HttpClient. I called rest API to get all courses:
/d2l/api/le/1.0/97578/classlist/
In this am getting users email id null. I want to integrate D2L email using Java client. Do we have any API for integrating D2L email using Java client?
For privacy reasons, the back-end LMS may be configured to prevent certain kinds of user data from appearing in the data retrieved in the classlist. This can include a user's email address.
It's possible, also, that the organizational unit (the course offering, in this case) has been configured not to expose users' email address through the classlist or similar API calls.

Resources