def get_backend_authenticated_client(username, backend):
"""Creates a new authenticated client for the user
and backend
@type username: str
@type backend: str
@rtype: api_server.clients.base_client.BaseAuthenticatedClient
@raises e: ClientError
@raises e: BackendsError
"""
try:
user = User.objects.get(username__iexact=username)
except User.DoesNotExist:
raise BackendsUserError('{} does not exist.'.format(username))
client = get_backend_client(backend)
try:
password = user.profile.get_credential(backend).get_password()
except Profile.NoCredentials:
raise BackendsUserError('{user} does not have access to {backend}.'.format(
user=username, backend=backend))
c, _ = client.login_or_register(
user.username, password, user.email)
return c
评论列表
文章目录