diff --git a/en/identity-server/next/docs/references/conditional-auth/api-reference.md b/en/identity-server/next/docs/references/conditional-auth/api-reference.md index e7c6c66cb0..65975059ed 100644 --- a/en/identity-server/next/docs/references/conditional-auth/api-reference.md +++ b/en/identity-server/next/docs/references/conditional-auth/api-reference.md @@ -35,6 +35,7 @@ - [`application`](#application) - [`userAgent`](#user-agent) - [`connectionMetadata`](#connectionmetadata) + - [`authConfig`](#authconfig) --- @@ -84,7 +85,8 @@ This method accepts an object as a parameter and should include the details list <eventCallbacks> (optional) The object that contains the callback functions, which are to be called based on the result of the step execution.
- Supported results are onSuccess and onFail, which can have their own optional callbacks as anonymous functions. + Supported results are onSuccess and onFail which can have their own optional callbacks as anonymous functions. For these callbacks, the [context](#context) and [data](#data) parameters are passed. + @@ -319,7 +321,7 @@ This function redirects the user to an error page. It includes the parameters li - + @@ -683,7 +685,7 @@ This function returns the local user associated with the federate username given ### HTTP GET -`httpGet(url, headers)` +`httpGet(url, headers, authConfig, eventHandlers)` The HTTP GET function enables sending HTTP GET requests to specified endpoints as part of the adaptive authentication scripts in WSO2 Identity Server. It's commonly used to interact with external systems or APIs to retrieve necessary data for authentication decisions. @@ -696,20 +698,37 @@ The HTTP GET function enables sending HTTP GET requests to specified endpoints a - + + + + + + + + +
urlurl The URL of the error page that the user is redirected to. If the value is null, the user is redirected by default to the retry.do error page.
Note that any relative URL is assumed to be relative to the host's root.
The URL of the endpoint to which the HTTP GET request should be sent.
headersheaders HTTP request headers to be included in the GET request (optional).
authConfigAn object containing the necessary authentication metadata to invoke the API. See [AuthConfig](#authconfig) for information.
eventHandlersThe object that contains the callback functions, which are to be called based on the result of the GET request.
+ Supported results are onSuccess and onFail, which can have their own optional callbacks as anonymous functions. +
- **Example** ``` js - function onLoginRequest(context) { + var authConfig = { + type: "basic", + properties: { + username: "admin", + password: "adminPassword" + } + }; + + var onLoginRequest = function(context) { httpGet('https://example.com/resource', { - "Authorization": "Bearer token", "Accept": "application/json" - }, { + }, authConfig, { onSuccess: function(context, data) { Log.info('httpGet call succeeded'); context.selectedAcr = data.status; @@ -724,17 +743,9 @@ The HTTP GET function enables sending HTTP GET requests to specified endpoints a } ``` -!!! note - To restrict HTTP GET requests to certain domains, configure the `deployment.toml` file as follows: - - ``` toml - [authentication.adaptive] - http_function_allowed_domains = ["example.com", "api.example.org"] - ``` - ### HTTP POST -`httpPost(url, body, headers)` +`httpPost(url, body, headers, authConfig, eventHandlers)` The HTTP POST function enables sending HTTP POST requests to specified endpoints as part of the adaptive authentication scripts in WSO2 Identity Server. It's commonly used to interact with external systems or APIs to retrieve necessary data for authentication decisions. @@ -754,41 +765,104 @@ The HTTP POST function enables sending HTTP POST requests to specified endpoints headers HTTP request headers to be included in the POST request (optional). + + authConfig + Authentication configuration to be included in the GET request (optional). + + + eventHandlers + The object that contains the callback functions, which are to be called based on the result of the GET request.
+ Supported results are onSuccess and onFail, which can have their own optional callbacks as anonymous functions. + + - - **Example** +- **Example** + + ``` + var authConfig = { + type: "clientcredential", + properties: { + consumerKey: "clientId", + consumerSecret: "clientSecret", + tokenEndpoint: "https://token-endpoint.com/token" + } + }; + + var onLoginRequest = function(context) { + httpPost('https://example.com/resource', { + "email": "test@wso2.com" + }, { + "Authorization": "Bearer token", + "Accept": "application/json" + }, authConfig, { + onSuccess: function(context, data) { + Log.info('httpPost call succeeded'); + context.selectedAcr = data.status; + executeStep(1); + }, + onFail: function(context, data) { + Log.info('httpPost call failed'); + context.selectedAcr = 'FAILED'; + executeStep(2); + } + }); + } + ``` - ``` js - function onLoginRequest(context) { - httpPost('https://example.com/resource', { - "email": "test@wso2.com" - }, { - "Authorization": "Bearer token", - "Accept": "application/json" - }, { - onSuccess: function(context, data) { - Log.info('httpPost call succeeded'); - context.selectedAcr = data.status; - executeStep(1); - }, - onFail: function(context, data) { - Log.info('httpPost call failed'); - context.selectedAcr = 'FAILED'; - executeStep(2); - } - }); - } - ``` - !!! note - To restrict HTTP POST requests to certain domains, configure the `deployment.toml` file as follows: + To restrict HTTP GET requests to certain domains, for `httpGet` and `httpPost` functions in adaptive authentication scripts, update the `deployment.toml` file as follows: - ``` toml + ```toml [authentication.adaptive] http_function_allowed_domains = ["example.com", "api.example.org"] ``` + To fine-tune connections initiated by WSO2 Identity Server to external services, you may add the following configurations to the `deployment.toml` file located in the `/repository/conf/` directory + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDescriptionDefault Value
http_connections.read_timeoutThe maximum time (in milliseconds) the server will wait for a response from the external service.3000 ms
http_connections.request_timeoutThe maximum time (in milliseconds) the server will wait to obtain a connection from the connection pool.1000 ms
http_connections.connection_timeoutThe maximum time (in milliseconds) the server will wait to establish a connection to the external service.3000 ms
http_connections.request_retry_countSpecifies the number of retry attempts for token requests initiated for authentication from client credentials.2
+ + Sample configuration is as follows: + + ```toml + [authentication.adaptive] + http_connections.read_timeout = 6000 + http_connections.request_timeout = 3000 + http_connections.connection_timeout = 3000 + http_connections.request_retry_count = 2 + ``` + ## Object reference ### Context @@ -965,3 +1039,64 @@ Contains the authentication step information. It may be a null or invalid step n This is the device property that is extracted from the raw userAgent string. + +You can securely store consumer keys and secrets as **secrets** in conditional authentication scripts and refer to +them in your conditional authentication scripts using the `secrets.{secret name}` syntax. For example, to retrieve a secret value, you may use: +```angular2html +var consumerSecret = secrets.clientSecret; +``` +For more information on adding secrets, refer to the [Add a secret to the script]({{base_path}}/guides/authentication/conditional-auth/configure-conditional-auth/#add-a-secret-to-the-script) section in the +documentation. + +### AuthConfig + +When using httpGet or httpPost functions in adaptive authentication scripts, the table summarizes each +authentication type and its required properties: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Authentication TypePropertiesDescription
basicusername, passwordUses user credentials.
apikeyapiKey, headerNameUses an API key sent as a header.
clientcredentialconsumerKey, consumerSecret, tokenEndpoint, scope (optional, a space separated list of scopes)Uses client credentials to obtain an access token.
bearertokenUses a bearer token for authentication.
+ +You can securely store sensitive values of properties like username, password, consumerKey, consumerSecret as secrets in conditional authentication scripts and refer to them in your conditional authentication scripts using the `secrets.{secret name}` syntax. For example, to retrieve a secret value, you can use: +```angular2html +var consumerSecret = secrets.clientSecret; +``` + +For more information on adding secrets, refer to the [Add a secret to the script]({{base_path}}/guides/authentication/conditional-auth/configure-conditional-auth/#add-a-secret-to-the-script) section in the documentation. + +### Data + + + + + + +
dataThe response data is a JSON object that contains the response data from the API call.
diff --git a/en/includes/guides/authentication/conditional-auth/configure-conditional-auth.md b/en/includes/guides/authentication/conditional-auth/configure-conditional-auth.md index b0c78eae9a..85fc8fc5a2 100644 --- a/en/includes/guides/authentication/conditional-auth/configure-conditional-auth.md +++ b/en/includes/guides/authentication/conditional-auth/configure-conditional-auth.md @@ -24,8 +24,6 @@ There are two ways to add a conditional authentication script: - Use a [predefined template]({{base_path}}/guides/authentication/conditional-auth/#script-templates). - Write a [new conditional auth script]({{base_path}}/guides/authentication/conditional-auth/write-your-first-script/). -{% if product_name == 'Asgardeo' %} - ## Add a secret to the script Secrets securely store values associated with external APIs. These secret values are used in conditional authentication scripts when {{ product_name }} is required to interact with an external API (service endpoint) during the authentication process. You can securely store these secret values on the {{ product_name }} Console and retrieve them whenever required for `callChoreo()` conditional authentication function. @@ -119,5 +117,3 @@ To delete an existing secret: 4. Click the trash icon next to the secret you wish to delete. 5. Select the checkbox and confirm your action. - -{% endif %}