Exemple #1
0
def set_authorization(r_dict, request):
    auth_params = r_dict['headers']['Authorization']
    if auth_params[:6] == 'OAuth ':
        # Make sure it has the required/valid oauth headers
        if CheckOAuth.is_valid_request(request):
            try:
                consumer, token, parameters = CheckOAuth.validate_token(
                    request)
            except OAuthError, e:
                raise OauthUnauthorized(send_oauth_error(e))
            # Set consumer and token for authentication piece
            r_dict['auth']['oauth_consumer'] = consumer
            r_dict['auth']['oauth_token'] = token
            r_dict['auth']['type'] = 'oauth'
        else:
            raise OauthUnauthorized(
                send_oauth_error(
                    OAuthError(_('Invalid OAuth request parameters.'))))

        # Used for OAuth scope
        endpoint = request.path[5:]
        # Since we accept with or without / on end
        if endpoint.endswith("/"):
            endpoint = endpoint[:-1]
        r_dict['auth']['endpoint'] = endpoint
Exemple #2
0
def parse(request, more_id=None):
    r_dict = {}

    # Build headers from request in request dict
    r_dict = get_headers(request.META, r_dict)
    
    # Traditional authorization should be passed in headers
    if 'Authorization' in r_dict:
        # OAuth will always be dict, not http auth. Set required fields for oauth module and lrs_auth for authentication
        # module
        auth_params = r_dict['Authorization']
        if auth_params[:6] == 'OAuth ':
            # Make sure it has the required/valid oauth headers
            if CheckOAuth.is_valid_request(request):
                try:
                    consumer, token, parameters = CheckOAuth.validate_token(request)
                except OAuthError, e:
                    raise OauthUnauthorized(send_oauth_error(e))
                # Set consumer and token for authentication piece
                r_dict['oauth_consumer'] = consumer
                r_dict['oauth_token'] = token
                r_dict['lrs_auth'] = 'oauth'
            else:
                raise OauthUnauthorized(send_oauth_error(OAuthError(_('Invalid request parameters.'))))

            # Used for OAuth scope
            endpoint = request.path[5:]
            # Since we accept with or without / on end
            if endpoint.endswith("/"):
                endpoint = endpoint[:-1]
            r_dict['endpoint'] = endpoint
        else:
            r_dict['lrs_auth'] = 'http'
 def is_authenticated(self, request):
     if CheckOAuth.is_valid_request(request):
         try:
             consumer, token, parameters = CheckOAuth.validate_token(request)
         except OAuthError, e:
             return (False, self.make_challenge(e))
         if self.resource_name and token.resource.name != self.resource_name:
             err = OAuthError(_('You are not allowed to access this resource.'))
             return (False, self.make_challenge(err))
         elif consumer and token:
             request.user = token.user
             return (True, None)
Exemple #4
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     if default_is_request_api(request):
         request.__class__.user = LazyAnonUser()
     resource_name = getattr(request, 'oauth_resource_name', None)
     if CheckOAuth.is_valid_request(request):
         try:
             consumer, token, parameters = CheckOAuth.validate_token(request)
         except OAuthError, e:
             return None
             #!! ??return send_oauth_error(e)
         if resource_name and token.resource.name != resource_name:
             return send_oauth_error(OAuthError(_('You are not allowed to access this resource.')))
         elif consumer and token:
             if token.user:
                 request.__class__.user = token.user
def set_authorization(r_dict, request):
    auth_params = r_dict['headers']['Authorization']
    if auth_params[:6] == 'OAuth ':
        # Make sure it has the required/valid oauth headers
        if CheckOAuth.is_valid_request(request):
            try:
                consumer, token, parameters = CheckOAuth.validate_token(request)
            except OAuthError, e:
                raise OauthUnauthorized(send_oauth_error(e))
            # Set consumer and token for authentication piece
            r_dict['auth']['oauth_consumer'] = consumer
            r_dict['auth']['oauth_token'] = token
            r_dict['auth']['type'] = 'oauth'
        else:
            raise OauthUnauthorized(send_oauth_error(OAuthError(_('Invalid OAuth request parameters.'))))

        # Used for OAuth scope
        endpoint = request.path[5:]
        # Since we accept with or without / on end
        if endpoint.endswith("/"):
            endpoint = endpoint[:-1]
        r_dict['auth']['endpoint'] = endpoint
Exemple #6
0
def set_authorization(r_dict, request):
    auth_params = r_dict["headers"]["Authorization"]
    if auth_params[:6] == "OAuth ":
        # Make sure it has the required/valid oauth headers
        if CheckOAuth.is_valid_request(request):
            try:
                consumer, token, parameters = CheckOAuth.validate_token(request)
            except OAuthError, e:
                raise OauthUnauthorized(send_oauth_error(e))
            # Set consumer and token for authentication piece
            r_dict["auth"]["oauth_consumer"] = consumer
            r_dict["auth"]["oauth_token"] = token
            r_dict["auth"]["type"] = "oauth"
        else:
            raise OauthUnauthorized(send_oauth_error(OAuthError(_("Invalid OAuth request parameters."))))

        # Used for OAuth scope
        endpoint = request.path[5:]
        # Since we accept with or without / on end
        if endpoint.endswith("/"):
            endpoint = endpoint[:-1]
        r_dict["auth"]["endpoint"] = endpoint
Exemple #7
0
 def check_request(self, request):
     if CheckOAuth.is_valid_request(request):
         try:
             CheckOAuth.validate_token(request)
         except OAuthError, e:
             return send_oauth_error(e)
Exemple #8
0
 def check_request(self, request):
     if CheckOAuth.is_valid_request(request):
         try:
             CheckOAuth.validate_token(request)
         except OAuthError, e: 
             return send_oauth_error(e)
Exemple #9
0
 def login(self, request):
     if CheckOAuth.is_valid_request(request):
         try:
             consumer, token, parameters = CheckOAuth.validate_token(request) 
         except OAuthError, e: 
             return  send_oauth_error(e)