Get unread message count from gmail

277 views
Skip to first unread message

Debarupa De

unread,
Feb 6, 2012, 5:49:38 PM2/6/12
to DotNetOpenAuth
I am working on an asp.net project that uses DotNetOpenAuth to login
users to the website with their gmail address, now the next request is
to get the unread email count from their inbox after they log in. Is
it possible? If yes, how?

Thanks for any help in advance!

Andrew Arnott

unread,
Feb 6, 2012, 8:09:30 PM2/6/12
to dotnet...@googlegroups.com
First we have to clarify: no part of DotNetOpenAuth allows you to login users using their gmail address.

So I'll assume you mean that you use OpenID to allow users to log in using their Google account (which may have any email address, not just @gmail.com).  

Once that assumption is made, your original question no longer sounds totally sound -- you want unread messages for what email box? The gmail.com box may or may not exist.  

So I'll make another assumption: you want to not only log users in with their Google Account, but you want to ask Google for their email address, validate that it is in fact a @gmail.com address, and if so, look up their unread message count.

One more question: do you really want to log in your users as described above, only accepting them if they happen to use Google and use @gmail.com email addresses, or do you want to allow users to log in with any OpenID from any OpenID Provider, and offer a service to your users of reporting their unread Gmail message counts independent of how they happened to log into your service?

OAuth must be used to look up unread message counts, and it requires that the user approve a request from your application to have that access.  If you're only interested in the unread mail count of your user and not interested in how they log in, then pure OAuth will be the answer.  If you also actually do want to log the user into your web application using only Google accounts that have @gmail.com email addresses, then an OpenID+OAuth hybrid is the ticket for you.

So before I go further, please tell us which scenario you fit into.
--
You received this message because you are subscribed to the Google Groups "DotNetOpenAuth" group.
To post to this group, send email to dotnet...@googlegroups.com.
To unsubscribe from this group, send email to dotnetopenid...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotnetopenid?hl=en.



--
--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre

Debarupa De

unread,
Feb 7, 2012, 1:25:23 PM2/7/12
to DotNetOpenAuth

On Feb 6, 5:09 pm, Andrew Arnott <andrewarn...@gmail.com> wrote:
> First we have to clarify: no part of DotNetOpenAuth allows you to login
> users using their gmail address.
>
> So I'll assume you mean that you use OpenID to allow users to log in using
> their Google account (which may have *any* email address, not just @
> gmail.com).

Sorry, I am very new to this. You are indeed correct, I am using
OpenIdButton with Identifier="https://www.google.com/accounts/o8/id"
to log the users in. The assemly that OpenIdButton uses is
DotNetOpenAuth so I thought it was actually DotNetOpenAuth, my
mistake:)
>
> Once that assumption is made, your original question no longer sounds
> totally sound -- you want unread messages for what email box? The
> gmail.combox may or may not exist.

After they log in, I'm checking if the email address falls under a
list of domains (our company uses google acounts but with it's own
domain name so for example, an email address may look like
a...@ourcompanydomain.com). So in this case I am checking if the logged
in email address has ourcompanydomain.com in it.

>
> So I'll make another assumption: you want to not only log users in with
> their Google Account, but you want to ask Google for their email address,
> validate that it is in fact a @gmail.com address, and if so, look up their
> unread message count.
>
No, I don't want to do that.

> One more question: do you really want to *log in* your users as described
> above, only accepting them if they happen to use Google and use
> @gmail.comemail addresses, or do you want to allow users to log in
> with
> *any* OpenID from any OpenID Provider, and offer a service to your users of
> reporting their unread Gmail message counts independent of how they
> happened to log into your service?

No, only the email address with the given domain names will be allowed
to access the website, else anybody can log in with a valid OpenID
from any OpenID provider but only the ones within the given domain(s)
will be able to access the webpages.
>
> OAuth must be used to look up unread message counts, and it requires that
> the user approve a request from your application to have that access.  If
> you're only interested in the unread mail count of your user and not
> interested in how they log in, then pure OAuth will be the answer.  If
> you *also
> *actually do want to log the user into your web application using only
> Google accounts that have @gmail.com email addresses, then an OpenID+OAuth
> hybrid is the ticket for you.
After the users log in (and after verifying that they have certain
roles to access certain parts of the website), a count of their unread
messages from their inbox should be displayed.
Please let me know if I was clear enough or if you need any other
details.
>
> So before I go further, please tell us which scenario you fit into.

Thanks a lot for your help!.
>
>
>
>
>
>
>
>
>
> On Monday, February 6, 2012, Debarupa De wrote:
> > I am working on an asp.net project that uses DotNetOpenAuth to login
> > users to the website with their gmail address, now the next request is
> > to get the unread email count from their inbox after they log in. Is
> > it possible? If yes, how?
>
> > Thanks for any help in advance!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "DotNetOpenAuth" group.
> > To post to this group, send email to dotnet...@googlegroups.com<javascript:;>
> > .
> > To unsubscribe from this group, send email to
> > dotnetopenid...@googlegroups.com <javascript:;>.

Debarupa De

unread,
Feb 8, 2012, 2:37:42 PM2/8/12
to DotNetOpenAuth
> OAuth must be used to look up unread message counts, and it requires that
> the user approve a request from your application to have that access. If
> you're only interested in the unread mail count of your user and not
> interested in how they log in, then pure OAuth will be the answer. If
> you *also
> *actually do want to log the user into your web application using only
> Google accounts that have @gmail.com email addresses, then an OpenID+OAuth
> hybrid is the ticket for you.

Could you give me an example of how to use OAuth to look up unread
message counts for the logged in users? I know it's possible if you
have the username/password for the user, but is there a way to do it
with the ClaimedIdentifier?

Thank you so much!

Andrew Arnott

unread,
Feb 18, 2012, 4:18:07 PM2/18/12
to dotnet...@googlegroups.com
Using email address as the key to control access is not what OpenID 2.0 was designed for.  I can't immediately think of any problems with doing that in your case though, so long as you verify that the OP Identifier in the assertion is indeed from Google.  You can do this with IAuthenticationResponse.Provider.Uri == "https://wwww.google.com/accounts/o8/ud" in your authenticate action (the URL is from memory, you may need to check to see what it tends to be and then write code to make sure it's always that value).  

Claimed Identifiers do not serve as authorization to do anything.  They merely identify the user to your web site.  If you want to then read that Google account's unread email count, you need an OAuth token.  You can do this by attaching an OAuth extension to the OpenID login request (DotNetOpenAuth.OpenId.Extensions.OAuth.AuthorizationRequest) that includes the proper "scope" value that indicates you want to access the user's email.  Then when the login is successful there will be an AuthorizationApprovedResponse extension in the response (if the user approved) that you can use to get an OAuth 1.0 access token, which you can then use to obtain the email information you want from Google.

You can look at a sample OpenID+OAuth that downloads the logging in user's Google Contacts in the OpenIdRelyingPartyWebForms\loginPlusOAuth.aspx sample.  Please direct questions about how to change this sample to download different information from Google to Google-specific forums or find the GData documentation Google publishes that teaches how to do this.
--
You received this message because you are subscribed to the Google Groups "DotNetOpenAuth" group.
To post to this group, send email to dotnet...@googlegroups.com.
To unsubscribe from this group, send email to dotnetopenid...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotnetopenid?hl=en.

Debarupa De

unread,
Feb 23, 2012, 3:00:49 PM2/23/12
to DotNetOpenAuth
> You can look at a sample OpenID+OAuth that downloads the logging in user's
> Google Contacts in the OpenIdRelyingPartyWebForms\loginPlusOAuth.aspx
> sample. Please direct questions about how to change this sample to
> download different information from Google to Google-specific forums or
> find the GData documentation Google publishes that teaches how to do this.

I followed it and it works like a charm but can't get it to work with
gmail; always getting "The remote server returned an error: (401)
Unauthorized." error at the line:
var response =
consumer.Channel.WebRequestHandler.GetResponse(request);

For clarification, the request is:
var request = consumer.PrepareAuthorizedRequest(GetGmailEndpoint,
accessToken, extraData); where GetGmailEndpoint is defined as:
private static readonly MessageReceivingEndpoint GetGmailEndpoint =
new MessageReceivingEndpoint("https://mail.google.com/mail/feed/atom/
Inbox", HttpDeliveryMethods.GetRequest);

Also, this same approach works most of the time with the calendar
feed, the other times I get the same error. When I use the OAuth
playground with my websites credentials, I get a "302 Moved
Temporarily" error.

I have been searching for a decent solution in asp.net for about a
week now that will at least get the unread message count but haven't
have any luck yet.

Andrew Arnott

unread,
Feb 23, 2012, 8:08:04 PM2/23/12
to dotnet...@googlegroups.com
I'm afraid I can't help you on this one.  Hopefully someone else, perhaps from a Google forum, can help.
--
You received this message because you are subscribed to the Google Groups "DotNetOpenAuth" group.
To post to this group, send email to dotnet...@googlegroups.com.
To unsubscribe from this group, send email to dotnetopenid...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotnetopenid?hl=en.

Reply all
Reply to author
Forward
0 new messages