Authentication Service#

Module part of the core componenets for the Factiva Analytics python package. Contains classes and tools that allow to interact with the authentication and authorization elements of the Factiva Analytics API.

UserKey#

class factiva.analytics.auth.userkey.UserKey(key=None)#

Class that represents an API user and can be instantiated based on the user-key value provided by the Dow Jones Developer Support team.

get_cloud_token() bool#

Request a cloud token and stores its content in the cloud_token property

Returns:

True if the operation was completed successfully. False otherwise.

Return type:

bool

OAuthUser#

class factiva.analytics.auth.oauthuser.OAuthUser(client_id: str | None = None, username: str | None = None, password: str | None = None)#

Class that represents a Dow Jones OAuth user.

Parameters:
  • client_id (str) – Assigned Client ID and communicated via the Welcome Letter. Retrieves the value from the ENV variable FACTIVA_CLIENTID it not provided.

  • username (str) – Assigned Username and communicated via the Welcome Letter. Retrieves the value from the ENV variable FACTIVA_USERNAME it not provided.

  • password (str) – Assigned password and communicated via the Welcome Letter. Retrieves the value from the ENV variable FACTIVA_PASSWORD it not provided.

Examples

Create an OAuthUser instance from ENV variables and assign the JWT token to a request headers dictionary.

from factiva.analytics import OAuthUser
o = OAuthUser()
headers = {
    'Authorization': f'Bearer {o.current_jwt_token}'
}

Shows the relevant properties of a OAuthUser instance.

from factiva.analytics import OAuthUser
o = OAuthUser()
o

output

<'factiva.analytics.OAuthUser'>
|-client_id = ****************************4Cs6
|-username = 9ZZZ000000-svcaccount@dowjones.com
|-password = ************gRk3
|-token_status = not_authenticated
property current_jwt_token#

Returns a valid token to be used in the Authorization HTTP header. Recalculates the JWT token automatically if needed.

get_id_token() bool#

Requests an ID token to the DJ auth service (authentication operation) and store the necessary information for furher requests in the relevant instance properties.

Returns:

True if the operation was completed successfully. False otherwise.

Return type:

bool

get_jwt_token() bool#

Requests a JWT Authorization token to the Factiva Auth service. The returned token is stored internally and available via the current_jwt_token property. Usual expiration is 1 hour (3600 seconds).

Returns:

True if the operation was completed successfully. False otherwise.

Return type:

bool

property token_status: str#

Provides the current token status:

  • not_authenticated (get_id_token() has not been executed)

  • id_token_expired (previously obtained ID token has expired)

  • not_authorized (get_jwt_token() has not been executed)

  • jwt_token_expired (previously obtained JWT token has expired)

  • OK (token is ready for authenticated requests)