using docs , python libraries google provided in oauth2client.py along oauth2.py library , docs managed send mail via user's gmail account authenticating them through oauth2.0. created project in google apis , able keys , other params needed correctly authenticate , send mail.
now trying achieve same goal google marketplace app. end-goal domain administrator add our app google apps domain each user not need go through authentication process , our app 'automatically' authorized send mail on behalf.
the first problem came in when registering app in marketplace, given client key , secret, no redirect_uri
, given in other project. means unable authenticate using oauth2webserverflow
class. lead hours of searching , conflicting answers , broken links within google's documentation. this doc leads me believe marketplace apps don't support oauth 2.0 , need go using 2-legged oauth 1.0 authentication. updated on year ago , other google docs tell me not use oauth 1.0 it's been deprecated.
is re-writing new code (not being able use same libraries or anything) use oauth 1.0 way able marketplace app? there way , if not, advice on leveraging existing code or how best in in current system?
a short snippet of how i'm doing using oauth 2.0:
flow = oauth2webserverflow( client_id="xxx", client_secret="xxx", scope="https://mail.google.com/", user_agent="mytest/0.1", redirect_uri="http://127.0.0.1:5000/oauth2callback" ) authorize_url = flow.step1_get_authorize_url()
and on return
credentials = flow.step2_exchange(request.args['code']) storage = storage(request.user.email) storage.put(credentials)
and send mail
conn = smtplib.smtp('smtp.googlemail.com', 587) conn.set_debuglevel(true) conn.ehlo('test') conn.starttls() auth_string = 'user=%s\1auth=bearer %s\1\1' % (user_address, credentials.access_token) conn.docmd('auth', 'xoauth2 ' + base64.b64encode(auth_string)) header = 'to:' + recipient_address + '\n' header += 'from:' + user_address + '\n' header += 'subject: oauth test email \n' header += 'content-type: text/html; charset=utf-8\n' msg = header + '\n ' + "waka waka" + ' \n\n' conn.sendmail(user_address, recipient_address, msg)
if had 50 points, i'd answer comment, since won't full answer.
i've been wrestling similar problems. came realization better off (more in control) if interacted apis directly using 'urllib2' , 'shelve' messing pseudo-helper stuff oauth2webserverflow , storage.
doing allows me check assumptions 'curl' command line, , code result in python. can tap wealth of blogs , q & oauth google without fragmentation different spotilly supported libraries (jave, c#, php, etc.)
i have written fork anton burnashev's "gspread".
this "pull request"
you should see alter nothing of burnashev's code. provide oauth stuff, , "installed applications"
there 6 different modalities :
- login
- web server applications
- client-side applications
- installed applications
- devices
- service accounts
how you using right one? took me lot of puzzling realize mine needed "installed app", i'm realizing should support "devices"