Authenticating and using the CCX-deployment API
To use the CCX-deployment API, you need to initialize and connect to the Content Platform Engine environment before you export or import application assets.
About this task
Initializing the CCX-deployment API
You need to initialize the CCX-deployment API for your Content Platform Engine environment before you export or import application assets.
Procedure
Connecting the CCX-deployment API to CSGQL Services
You can configure authentication options based on how your Content Platform Engine environment is configured.
About this task
For authentication and related configuration parameters, it is convenient to capture the settings
in a module named, for example, config. The sample code for calling the CCX-deployment API uses this technique. The example code
that is discussed in the task assume the use of a config module.
Procedure
GraphQLConnection object and call the initialize method of
the GraphQLConnection class for your authentication type. - OAuth based authentication
For OAuth based authentication, initialize the
GraphQLConnectionconnection object and call theconn.initialize_oauth()method.
Theconn = GraphqlConnection(url=config.GQL_URL, token_url=config.TOKEN_URL) conn.initialize_oauth( client_id=config.CLIENT_ID, client_secret= config.CLIENT_SECRET, username=config.OAUTH_USERNAME, password=config.OAUTH_PASSWORD, grant_type=config.GRANT_TYPE, scope=config.SCOPE) conn.get_token()conn.initialize_oauth()returns two tokens - an XSRF token, and an access token. Theconn.xsrf_tokenmember holds the XSRF token, which is used to prevent cross-site request forgery (CSRF) attacks.The
conn.tokenmember holds the access token, which is used for authentication. When a GraphQL request is made, you must include theconn.xsrf_tokenand theconn.tokentoken in the request header. - Basic authenticationFor basic authentication, initialize the
GraphQLConnectionconnection object and call theconn.initialize_basic()method.
Theconn = GraphqlConnection(url=config.GQL_URL) conn.initialize_basic(username=config.BASIC_USERNAME, password=config.BASIC_PASSWORD)conn.initialize_basic()returns theconn.xsrf_tokenmember holds the XSRF token, which is used to prevent cross-site request forgery (CSRF) attacks. The basic authentication credentials are also sent as the authentication header with each request. - Zen and IAM based authenticationFor Zen and IAM based authentication, initialize the
GraphQLConnectionconnection object and call theconn.initialize_zen_iam()method.
Theconn = GraphqlConnection(url=config.GQL_URL, token_url=config.TOKEN_URL) conn.initialize_zen_iam(zen_exchange_url=config.EXCHANGE_TOKEN_URL, iam_client_id=config.CLIENT_ID, iam_client_secret= config.CLIENT_SECRET, iam_username=config.OAUTH_USERNAME, iam_password=config.OAUTH_PASSWORD, iam_grant_type=config.GRANT_TYPE, iam_scope=config.SCOPE) conn.get_token()conn.initialize_zen_iam()returns theconn.xsrf_tokenand theconn.tokenmembers that are sent with each GraphQL request. - (V5.6 iF001 and later) Zen API key-based authenticationFor Zen API key-based authentication, initialize the
GraphQLConnectionconnection object and call theinitialize_zen_api()method.
Theconn = GraphqlConnection(url=config.GQL_URL, token_url=config.TOKEN_URL) conn.initialize_zen_api( username=config.ZEN_USERNAME, apikey=config.ZEN_APIKEY) conn.get_token()conn.initialize_zen_api()returns theconn.xsrf_tokenandconn.tokenmembers that are sent with each GraphQL request.