def __init__(self,
              request_validator,
              token_expires_in=None,
              token_generator=None,
              refresh_token_generator=None,
              *args,
              **kwargs):
     auth_grant = OrgAuthorizationCodeGrant(request_validator)
     implicit_grant = OrgImplicitGrant(request_validator)
     password_grant = OrgResourceOwnerPasswordCredentialsGrant(
         request_validator)
     credentials_grant = ClientCredentialsGrant(request_validator)
     refresh_grant = RefreshTokenGrant(request_validator)
     bearer = BearerToken(request_validator, token_generator,
                          token_expires_in, refresh_token_generator)
     AuthorizationEndpoint.__init__(self,
                                    default_response_type='code',
                                    response_types={
                                        'code': auth_grant,
                                        'token': implicit_grant,
                                    },
                                    default_token_type=bearer)
     TokenEndpoint.__init__(self,
                            default_grant_type='authorization_code',
                            grant_types={
                                'authorization_code': auth_grant,
                                'password': password_grant,
                                'client_credentials': credentials_grant,
                                'refresh_token': refresh_grant,
                            },
                            default_token_type=bearer)
     ResourceEndpoint.__init__(self,
                               default_token='Bearer',
                               token_types={'Bearer': bearer})
     RevocationEndpoint.__init__(self, request_validator)
 def __init__(self, request_validator, token_expires_in=None,
              token_generator=None, refresh_token_generator=None,
              *args, **kwargs):
     auth_grant = OrgAuthorizationCodeGrant(request_validator)
     implicit_grant = OrgImplicitGrant(request_validator)
     password_grant = OrgResourceOwnerPasswordCredentialsGrant(
         request_validator)
     credentials_grant = ClientCredentialsGrant(request_validator)
     refresh_grant = RefreshTokenGrant(request_validator)
     bearer = BearerToken(request_validator, token_generator,
                          token_expires_in, refresh_token_generator)
     AuthorizationEndpoint.__init__(self, default_response_type='code',
                                    response_types={
                                        'code': auth_grant,
                                        'token': implicit_grant,
                                    },
                                    default_token_type=bearer)
     TokenEndpoint.__init__(self, default_grant_type='authorization_code',
                            grant_types={
                                'authorization_code': auth_grant,
                                'password': password_grant,
                                'client_credentials': credentials_grant,
                                'refresh_token': refresh_grant,
                            },
                            default_token_type=bearer)
     ResourceEndpoint.__init__(self, default_token='Bearer',
                               token_types={'Bearer': bearer})
     RevocationEndpoint.__init__(self, request_validator)
	def __init__(self, request_validator, token_generator=None,
				 token_expires_in=None, refresh_token_generator=None, **kwargs):
		"""Construct a new web application server.

		:param request_validator: An implementation of
								  oauthlib.oauth2.RequestValidator.
		:param token_expires_in: An int or a function to generate a token
								 expiration offset (in seconds) given a
								 oauthlib.common.Request object.
		:param token_generator: A function to generate a token from a request.
		:param refresh_token_generator: A function to generate a token from a
										request for the refresh token.
		:param kwargs: Extra parameters to pass to authorization-,
					   token-, resource-, and revocation-endpoint constructors.
		"""
		auth_grant = AuthorizationCodeGrant(request_validator)
		refresh_grant = RefreshTokenGrant(request_validator)
		bearer = BearerToken(request_validator, token_generator,
							 token_expires_in, refresh_token_generator)
		AuthorizationEndpoint.__init__(self, default_response_type='code',
									   response_types={'code': auth_grant},
									   default_token_type=bearer)
		TokenEndpoint.__init__(self, default_grant_type='authorization_code',
							   grant_types={
								   'authorization_code': auth_grant,
								   'refresh_token': refresh_grant,
							   },
							   default_token_type=bearer)
		ResourceEndpoint.__init__(self, default_token='Bearer',
								  token_types={'Bearer': bearer})
		RevocationEndpoint.__init__(self, request_validator)
Example #4
0
	def __init__(self, request_validator, token_generator=None,
				 token_expires_in=None, refresh_token_generator=None, **kwargs):
		"""Construct a new web application server.

		:param request_validator: An implementation of
								  oauthlib.oauth2.RequestValidator.
		:param token_expires_in: An int or a function to generate a token
								 expiration offset (in seconds) given a
								 oauthlib.common.Request object.
		:param token_generator: A function to generate a token from a request.
		:param refresh_token_generator: A function to generate a token from a
										request for the refresh token.
		:param kwargs: Extra parameters to pass to authorization-,
					   token-, resource-, and revocation-endpoint constructors.
		"""
		auth_grant = AuthorizationCodeGrant(request_validator)
		refresh_grant = RefreshTokenGrant(request_validator)
		bearer = BearerToken(request_validator, token_generator,
							 token_expires_in, refresh_token_generator)
		AuthorizationEndpoint.__init__(self, default_response_type='code',
									   response_types={'code': auth_grant},
									   default_token_type=bearer)
		TokenEndpoint.__init__(self, default_grant_type='authorization_code',
							   grant_types={
								   'authorization_code': auth_grant,
								   'refresh_token': refresh_grant,
							   },
							   default_token_type=bearer)
		ResourceEndpoint.__init__(self, default_token='Bearer',
								  token_types={'Bearer': bearer})
		RevocationEndpoint.__init__(self, request_validator)
 def setUp(self):
     self.mock_validator = mock.MagicMock()
     self.addCleanup(setattr, self, 'mock_validator', mock.MagicMock())
     token = tokens.BearerToken(request_validator=self.mock_validator)
     self.endpoint = ResourceEndpoint(
         default_token='Bearer',
         token_types={'Bearer': token}
     )
Example #6
0
class ResourceEndpointTest(TestCase):
    def setUp(self):
        self.mock_validator = mock.MagicMock()
        self.addCleanup(setattr, self, "mock_validator", mock.MagicMock())
        token = tokens.BearerToken(request_validator=self.mock_validator)
        self.endpoint = ResourceEndpoint(default_token="Bearer", token_types={"Bearer": token})

    def test_defaults(self):
        uri = "http://a.b/path?some=query"
        self.mock_validator.validate_bearer_token.return_value = False
        valid, request = self.endpoint.verify_request(uri)
        self.assertFalse(valid)
        self.assertEqual(request.token_type, "Bearer")
Example #7
0
class ResourceEndpointTest(TestCase):
    def setUp(self):
        self.mock_validator = mock.MagicMock()
        self.addCleanup(setattr, self, 'mock_validator', mock.MagicMock())
        token = tokens.BearerToken(request_validator=self.mock_validator)
        self.endpoint = ResourceEndpoint(default_token='Bearer',
                                         token_types={'Bearer': token})

    def test_defaults(self):
        uri = 'http://a.b/path?some=query'
        self.mock_validator.validate_bearer_token.return_value = False
        valid, request = self.endpoint.verify_request(uri)
        self.assertFalse(valid)
        self.assertEqual(request.token_type, 'Bearer')