Beispiel #1
0
def _get_bearer_token(app, allowed_scopes, http_method, uri, body, headers, ttl=DEFAULT_TTL):
    validator = SPOauth2RequestValidator(app=app, allowed_scopes=allowed_scopes, ttl=ttl)
    server = Oauth2BackendApplicationServer(validator,
        token_generator=_generate_signed_token)

    headers, body, status = server.create_token_response(
        uri, http_method, body, headers, {})

    if status == 200:
        token_response = json.loads(body)
        return token_response.get('access_token')
    return None
Beispiel #2
0
def _authenticate_request(auth_type, app, allowed_scopes, http_method,
                          uri, body, headers, ttl=DEFAULT_TTL):
    if auth_type == 'Basic':
        validator = SPBasicAuthRequestValidator(app=app, headers=headers)
        valid, r = validator.verify_request()
        return valid, r
    if auth_type == 'Bearer':
        validator = SPOauth2RequestValidator(app=app, allowed_scopes=allowed_scopes, ttl=ttl)
        server = Oauth2BackendApplicationServer(validator)
        valid, r = server.verify_request(uri, http_method, body, headers, allowed_scopes)
        return valid, r
    return None, None
Beispiel #3
0
 def _authenticate_request(self, auth_type, scopes, http_method, uri, body,
                           headers, ttl):
     """Authenticates request based on auth type.
     """
     if auth_type == 'Basic':
         validator = SPBasicAuthRequestValidator(
             app=self.app, headers=headers)
         valid, result = validator.verify_request()
         return valid, result
     if auth_type == 'Bearer':
         validator = SPOauth2RequestValidator(
             app=self.app, allowed_scopes=scopes, ttl=ttl)
         server = Oauth2BackendApplicationServer(validator)
         valid, result = server.verify_request(
             uri, http_method, body, headers, scopes)
         return valid, result
     return None, None