pyvo
pyvo copied to clipboard
FEATURE: tools for Auth
CONTEXT
End-Users knows their token, and base URL and the Service they use. Not the API of pyvo.auth.
PROBLEM
Setting up an AuthSession is prone to Error for end-users:
Here is a minimal example
# Setup Session
tap_session = requests.Session()
tap_session.headers['Authorization'] = token
# Setup AuthSession
auth = AuthSession()
auth.credentials.set('service-token', tap_session)
auth.add_security_method_for_url(url, 'service-token')
auth.add_security_method_for_url(url + '/sync', 'service-token')
auth.add_security_method_for_url(url + '/async', 'service-token')
auth.add_security_method_for_url(url + '/tables', 'service-token')
# Create service
tap_service = vo.dal.TAPService(url, auth)
FEATURE REQUEST
A method to get/create the AuthSession object. Something like this:
def get_authsession_for_url(url, token, services=None, auth_key='service-tocken'):
'''Returns an AuthSession setup for the given url and services.
Parameters:
----------------
url: str
Base url for the security methods.
token: str
Token for the `Authorization` header
services: list[str], default=None
List of suffixes of the base url corresponding to the provided services.
auth_key: str, default='service-tocken'
Name of the credential. Key of the credential in the CredentialStore dictionary.
'''
# Setup Session
tap_session = requests.Session()
tap_session.headers['Authorization'] = token
# Setup AuthSession
auth = AuthSession()
auth.credentials.set(auth_key, tap_session)
auth.add_security_method_for_url(url, auth_key)
if services is not None:
for service in services:
auth.add_security_method_for_url(url + service, auth_key)
return(auth)