Пример #1
0
def main():
    auth = OAuthMethod(oauth_key, oauth_secret)
    auth.setRequestToken()
    print auth.buildAuthUrl()
    raw_input()
    auth.setAccessToken()
    reader = GoogleReader(auth)
    print reader.getUserInfo()
Пример #2
0
def startAuth(request):
    if request.method == 'POST':
        #start oauth request
        my_token  = settings.OAUTH_KEY
        my_secret = settings.OAUTH_SECRET
        auth = OAuthMethod(my_token, my_secret)

        callback  = settings.SERVER_HOST +  "share/"
        auth.setCallback(callback)

        token, token_secret = auth.setAndGetRequestToken()
        print token, token_secret
        request.session[token] = token_secret
        print auth.buildAuthUrl()
        return HttpResponseRedirect(auth.buildAuthUrl())
    else:
        return HttpResponse(500)
Пример #3
0
 def test_getting_request_token(self):
     auth = OAuthMethod(oauth_key, oauth_secret)
     token, token_secret = auth.setAndGetRequestToken()
     url = auth.buildAuthUrl()
     response = automated_oauth_approval(url)
     self.assertNotEqual(
         -1,
         response.get_data().find('You have successfully granted'))
Пример #4
0
    def test_full_auth_process_without_callback(self):
        auth = OAuthMethod(oauth_key, oauth_secret)
        auth.setRequestToken()
        auth_url = auth.buildAuthUrl()
        response = automated_oauth_approval(auth_url)
        auth.setAccessToken()
        reader = GoogleReader(auth)

        info = reader.getUserInfo()
        self.assertEqual(dict, type(info))
        self.assertEqual(firstname, info['userName'])
Пример #5
0
    def test_full_auth_process_without_callback(self):
        auth = OAuthMethod(oauth_key, oauth_secret)
        auth.setRequestToken()
        auth_url = auth.buildAuthUrl()
        response = automated_oauth_approval(auth_url)
        auth.setAccessToken()
        reader = GoogleReader(auth)

        info = reader.getUserInfo()
        self.assertEqual(dict, type(info))
        self.assertEqual(firstname, info['userName'])
Пример #6
0
    def test_full_auth_process_with_callback(self):
        auth = OAuthMethod(oauth_key, oauth_secret)
        #must be a working callback url for testing
        auth.setCallback("http://www.asktherelic.com")
        token, token_secret = auth.setAndGetRequestToken()
        auth_url = auth.buildAuthUrl()

        #callback section
        #get response, which is a redirect to the callback url
        response = automated_oauth_approval(auth_url)
        query_string = urlparse.urlparse(response.geturl()).query
        #grab the verifier token from the callback url query string
        token_verifier = urlparse.parse_qs(query_string)['oauth_verifier'][0]

        auth.setAccessTokenFromCallback(token, token_secret, token_verifier)
        reader = GoogleReader(auth)

        info = reader.getUserInfo()
        self.assertEqual(dict, type(info))
        self.assertEqual(firstname, info['userName'])
Пример #7
0
    def test_full_auth_process_with_callback(self):
        auth = OAuthMethod(oauth_key, oauth_secret)
        #must be a working callback url for testing
        auth.setCallback("http://www.asktherelic.com")
        token, token_secret = auth.setAndGetRequestToken()
        auth_url = auth.buildAuthUrl()

        #callback section
        #get response, which is a redirect to the callback url
        response = automated_oauth_approval(auth_url)
        query_string = urlparse.urlparse(response.geturl()).query
        #grab the verifier token from the callback url query string
        token_verifier = urlparse.parse_qs(query_string)['oauth_verifier'][0]

        auth.setAccessTokenFromCallback(token, token_secret, token_verifier)
        reader = GoogleReader(auth)

        info = reader.getUserInfo()
        self.assertEqual(dict, type(info))
        self.assertEqual(firstname, info['userName'])
Пример #8
0
 def test_getting_request_token(self):
     auth = OAuthMethod(oauth_key, oauth_secret)
     token, token_secret = auth.setAndGetRequestToken()
     url = auth.buildAuthUrl()
     response = automated_oauth_approval(url)
     self.assertNotEqual(-1,response.get_data().find('You have successfully granted'))