astropy / astropy/pyvo

FEATURE: tools for Auth

Open
#230 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
88
Forks
64
Avg merge
38m
Merged PRs (30d)
1

Description

# 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
```python
# 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:

```python
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)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating AuthSession, its CredentialStore, and add_security_method_for_url, then compare the proposed helper with their existing APIs. Done means a helper accepts a base URL, token, optional service suffixes, and credential name, returns a configured AuthSession, and covers the shown setup behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.