DataScript: avi.http.oauth_get_token

DataScript

Function avi.http.oauth_get_token(TOKEN_TYPE)
Description Extracts the token of TOKEN_TYPE from the user’s OAuth session after the session is established. The token (OAUTH_ACCESS_TOKEN or OAUTH_ID_TOKEN) can further be sent to the backend application.
Events HTTP_REQ
HTTP_RESP
HTTP_RESP_DATA
HTTP_POST_AUTH
RESP_FAILED
HTTP_REQ_DATA
LB_DONE
Parameter It takes a single parameter TOKEN_TYPE.
TOKEN_TYPE can be two types of OAuth tokens:
avi.OAUTH_ACCESS_TOKEN
avi.OAUTH_ID_TOKEN
Returns Requested token is returned as a string, if a token is present. Else, nil is returned.
Example Extracts token of TOKEN_TYPE (avi.OAUTH_ACCESS_TOKEN). If the token is found, it is sent to the backend under the authorization header.

token = avi.http.oauth_get_token(avi.OAUTH_ACCESS_TOKEN)
if token == nil then
  avi.vs.log("Token not found")
else
 avi.http.add_header("Authorization", token) 
end