Authentication information

Introduction

From any Python code, it is possible to retrieve information about the user or API key currently running this code.

This can be used:

  • From code running within a recipe or notebook, for the code to know who is running said code
  • From code running with a plugin recipe, for the code to know who is running said code
  • From code running outside of DSS, simply to retrieve details of the current API key

Furthermore, the API provides the ability, from a set of HTTP headers, to identify the user represented by these headers. This can be used in the backend of a webapp (either Bokeh or Flask), in order to securely identify which user is currently browsing the webapp.

Code samples

Basic usage

auth_info = client.get_auth_info()

# auth_info is a dict which contains at least a "authIdentifier" field, which is the login for a user
print ("User running this code is %s" % auth_info["authIdentifier"])

Reference documentation

DSSClient.get_auth_info(with_secrets=False)

Returns various information about the user currently authenticated using this instance of the API client.

This method returns a dict that may contain the following keys (may also contain others):

  • authIdentifier: login for a user, id for an API key
  • groups: list of group names (if context is an user)
  • secrets: list of dicts containing user secrets (if context is an user)
Param:with_secrets boolean: Return user secrets
Returns:a dict
Return type:dict
DSSClient.get_auth_info_from_browser_headers(headers_dict, with_secrets=False)

Returns various information about the DSS user authenticated by the dictionary of HTTP headers provided in headers_dict.

This is generally only used in webapp backends

This method returns a dict that may contain the following keys (may also contain others):

  • authIdentifier: login for a user, id for an API key
  • groups: list of group names (if context is an user)
  • secrets: list of dicts containing user secrets (if context is an user)
Param:headers_dict dict: Dictionary of HTTP headers
Param:with_secrets boolean: Return user secrets
Returns:a dict
Return type:dict