Ejemplo n.º 1
0
    def get_authorization_url(self, dynamodb):
        try:
            nonce = NonceUtil.generate(
                dynamodb=dynamodb,
                expiration_minites=settings.YAHOO_NONCE_EXPIRATION_MINUTES,
                provider='yahoo',
                type='nonce',
                length=settings.YAHOO_NONCE_LENGTH)
            state = NonceUtil.generate(
                dynamodb=dynamodb,
                expiration_minites=settings.YAHOO_NONCE_EXPIRATION_MINUTES,
                provider='yahoo',
                type='state',
                length=settings.YAHOO_NONCE_LENGTH)
        except (ClientError) as e:
            raise e
        authorization_endpoint = \
            self.endpoints['authorization_endpoint'] + \
            '?response_type=code' + \
            '&client_id=' + self.client_id + \
            '&scope=' + settings.YAHOO_LOGIN_REQUEST_SCOPE + \
            '&redirect_uri=' + self.callback_url + \
            '&nonce='+nonce+'&state='+state

        return authorization_endpoint
 def test_generate_ng(self):
     with self.assertRaises(ClientError):
         self.dynamodb.Table = MagicMock()
         self.dynamodb.Table.return_value.put_item.side_effect = ClientError(
             {'Error': {
                 'Code': 'xxxx'
             }}, 'operation_name')
         NonceUtil.generate(dynamodb=self.dynamodb,
                            expiration_minites=15,
                            provider='yahoo',
                            type='nonce',
                            length=10)
    def test_generate_ok(self):
        nonce = NonceUtil.generate(dynamodb=self.dynamodb,
                                   expiration_minites=15,
                                   provider='yahoo',
                                   type='nonce',
                                   length=10)

        table = self.dynamodb.Table(os.environ['NONCE_TABLE_NAME'])
        result = table.get_item(Key={'nonce': nonce}).get('Item')
        self.assertEqual(len(result), 4)
Ejemplo n.º 4
0
    def get_authorization_url(self, dynamodb):
        try:
            state = NonceUtil.generate(
                dynamodb=dynamodb,
                expiration_minites=settings.FACEBOOK_NONCE_EXPIRATION_MINUTES,
                provider='facebook',
                type='state',
                length=settings.FACEBOOK_NONCE_LENGTH)
        except (ClientError) as e:
            raise e

        authorization_endpoint = \
            settings.FACEBOOK_API_AUTHENTICATE_URL + \
            '?client_id=' + self.app_id + \
            '&redirect_uri=' + self.callback_url + \
            '&scope=' + settings.FACEBOOK_LOGIN_REQUEST_SCOPE + \
            '&state='+state

        return authorization_endpoint