Mercurial > public > sg101
comparison gcalendar/oauth.py @ 857:9165edfb1709
For issue #80, use new Google Calendar v3 API.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 22 Nov 2014 13:27:13 -0600 |
parents | 8743c566f712 |
children |
comparison
equal
deleted
inserted
replaced
856:c2dfd1b1323e | 857:9165edfb1709 |
---|---|
26 """Performs a stat() on the credentials file and returns the last modified | 26 """Performs a stat() on the credentials file and returns the last modified |
27 time as a datetime object. If an error occurs, None is returned. | 27 time as a datetime object. If an error occurs, None is returned. |
28 """ | 28 """ |
29 try: | 29 try: |
30 status = os.stat(settings.GCAL_CREDENTIALS_PATH) | 30 status = os.stat(settings.GCAL_CREDENTIALS_PATH) |
31 return datetime.datetime.fromtimestamp(status.st_mtime) | |
32 except OSError: | 31 except OSError: |
33 return None | 32 return None |
33 return datetime.datetime.fromtimestamp(status.st_mtime) | |
34 | 34 |
35 | 35 |
36 def get_auth_url(request, callback_url): | 36 def get_auth_url(callback_url): |
37 """ | 37 """ |
38 This function creates an OAuth flow object and uses it to generate an | 38 This function creates an OAuth flow object and uses it to generate an |
39 authorization URL which is returned to the caller. | 39 authorization URL which is returned to the caller. |
40 | |
41 request - the HttpRequest object for the user requesting the token. The | |
42 token is stored in the session object attached to this request. | |
43 | 40 |
44 callback_url - a string that is the URL that Google should redirect the user | 41 callback_url - a string that is the URL that Google should redirect the user |
45 to after the user has authorized our application access to their data. | 42 to after the user has authorized our application access to their data. |
46 | 43 |
47 """ | 44 """ |
67 return auth_url | 64 return auth_url |
68 | 65 |
69 | 66 |
70 def auth_return(request): | 67 def auth_return(request): |
71 """ | 68 """ |
72 This function should be called after Google has sent the user back to us | 69 This function should be called after Google has redirected the user |
73 after the user authorized us. We retrieve the authorization code from the | 70 after the user authorized us. We retrieve the authorization code from the |
74 request query parameters and then exchange it for access tokens. These | 71 request query parameters and then exchange it for access tokens. These |
75 tokens are stored in our credentials file. | 72 tokens are stored in our credentials file. |
76 | 73 |
77 If an error is encountered, an OAuthError is raised. | 74 If an error is encountered, an OAuthError is raised. |
109 storage = Storage(settings.GCAL_CREDENTIALS_PATH) | 106 storage = Storage(settings.GCAL_CREDENTIALS_PATH) |
110 storage.put(credentials) | 107 storage.put(credentials) |
111 logging.info("auth_return completed successfully") | 108 logging.info("auth_return completed successfully") |
112 | 109 |
113 | 110 |
114 def serialize_token(token): | 111 def get_credentials(): |
115 """ | 112 """Obtain the stored credentials if available, or None if they are not.""" |
116 This function turns a token into a string and returns it. | 113 storage = Storage(settings.GCAL_CREDENTIALS_PATH) |
117 | 114 return storage.get() |
118 """ | |
119 return gdata.gauth.TokenToBlob(token) | |
120 | |
121 | |
122 def deserialize_token(s): | |
123 """ | |
124 This function turns a string into a token returns it. The string must have | |
125 previously been created with serialize_token(). | |
126 | |
127 """ | |
128 return gdata.gauth.TokenFromBlob(s) |