owainlewis / clojure-mail

A Clojure library for parsing, downloading and reading email from IMAP servers.
203 stars 54 forks source link

Add Xoauth2 support #38

Closed danieltreacy closed 8 years ago

danieltreacy commented 8 years ago

This change adds a xoauth2-store helper function that allows a user to authenticate using an email address and an Oauth access token.

It also adds a Gmail-specific helper in the clojure-mail/gmail namespace that sets the Gmail IMAP server and protocol defaults.

The README has been updated with an example of usage.

owainlewis commented 8 years ago

Lovely. Thanks :+1:

cstrahan commented 8 years ago

Hey, this is pretty awesome! @owainlewis, do you suppose you could cut a release with this, please?

cstrahan commented 8 years ago

@danieltreacy I just gave this a try, but I'm having trouble authenticating. What is the oauth-token supposed to be? I have a client ID, client secret, and refresh token. Am I supposed to join those together in some way?

cstrahan commented 8 years ago

So, I started reading this: https://developers.google.com/gmail/xoauth2_protocol?hl=en

I think the problem is that I don't have the https://mail.google.com/ scope.

danieltreacy commented 8 years ago

@cstrahan You get an Oauth token from an application that is registered to authenticate users against the Gmail API. If you don't have your own application, you can generate a personal test token using the Google OAuth Playground (https://developers.google.com/oauthplayground/)

Make sure you select the right scopes (just select all of the URLs in the "Gmail API v1" dropdown, otherwise the authentication will fail.

The token to pass to xoauth-store is the access token generated in step 2, not the refresh token or authorization code.

danieltreacy commented 8 years ago

@cstrahan Didn't see your second post - yes, the missing scope would lead to an authentication failure :)

cstrahan commented 8 years ago

@danieltreacy Awesome, thanks! I'm not terribly familiar with OAuth, so I didn't grok the distinction until now. I read through how gmail-clj gets an access token, and used that to successfully create a store.

Thanks a ton!

owainlewis commented 8 years ago

@cstrahan Just pushed 1.0.4 release. Let me know if you have any issues. Thanks :+1: