FRAMES | NO FRAMES
getToken Method

Securely request a short-lived token with valid Business Analyst Online API credentials in order to use the Business Analyst Online API Services and Web SDKs.

string getToken ( 
    string  userID,
    string  password	
);

Parameter Description
userID User ID. Type String.
password User password. Type String.

Returns

Variable of type String.

After securely validating user credentials, the Business Analyst Online Get Token - Authentication endpoint will return a string-based response containing a short-lived token. This token, while valid, may be used to make Web services requests with the Business Analyst Online API REST and SOAP services and Flex and Silverlight Web SDKs.

Remarks

The Business Analyst Online API services and Web SDKs use a token-based authentication scheme to validate user access to the Business Analyst-based services and methods. Access to the various Business Analyst report templates and summarization variables can also vary based on the Business Analyst Online subscription type.

Initially, a user or application will submit a secure and encrypted request with a valid username and password to the Get Token - Authentication service. After the account credentials are validated, a short-lived token string will be returned to the calling user or application in the response. While valid, this token string will enable a user or application to submit Business Analyst SOAP and REST Web services requests and execute analysis services with the Web SDK components to the Business Analyst Online API.

Secure Sockets Layer (SSL) is a cryptographic protocol that manages the security and integrity of data traveling across the Internet. SSL is most commonly used between Web browsers and Web servers to create a secure communications link (e.g. Website URLs beginning with https://). SSL can also be used between client applications and Web services such as the Business Analyst Online Get Token - Authentication service. Many e-commerce Websites, such as banks and online stores, use SSL to encrypt a customer's payment and account information prior to its transfer across the Internet. This will minimize the chance that the sensitive data is intercepted and exploited by any individuals or applications.

The Business Analyst Online REST and SOAP APIs leverage SSL to securely and efficiently authenticate users and applications, and to issue a short-lived token. Subsequently, this token can be used to make Business Analyst Online SOAP and REST API Web services requests with the Business Analyst Online API Web SDKs until it times out. Currently, the tokens are set to timeout after 6 hours however; this is subject to change based on user feedback and ongoing performance evaluations.

See Using the BAOReportHelper Class for information about using the BAOReportHelper class which manages token renewal automatically.

Examples

In order to get an authentication token, add the Web reference to Business Analyst Online API Authentication WSDL (see Using Secured Web Services and Tokens). This Web Service uses SSL encryption and is secure. The example below shows how to get an authentication token from the Business Analyst Online API Authentication Web Service. See Using the BAOReportHelper Class for information about using the BAOReportHelper class which manages token renewal automatically.

Example 1: Using the Get Token Method through the Business Analyst Online API SOAP Authentication Class

Notes: This endpoint also uses SSL encryption and is secure.

Download complete source code as Visual Studio solution to immediately execute samples. (See GetTokenExamples.getTokenExample1 in source.)


Example (1) Code
C#
// Authentication: Uses Authentication proxy class to generate token.

// Business Analyst Online API Sample credentials.
// NOTE: These credentials are associated with an 
// account which constrains analysis to the
// two ZIP codes in Redlands, CA.
string username = "BAOAPISAMPLE"; // Substitute user name here
string password = "baoapisample"; // Substitute password here

Authentication auth = new Authentication();
string token = auth.getToken(username, password);

Example (1) Code
VB.NET
' Authentication: Uses Authentication proxy class to generate token.

' Business Analyst Online API Sample credentials.
' NOTE: These credentials are associated with an 
' account which constrains analysis to the
' two ZIP codes in Redlands, CA.
Dim username As String = "BAOAPISAMPLE"
' Substitute user name here
Dim password As String = "baoapisample"
' Substitute password here
Dim auth As New Authentication()
Dim token As String = auth.getToken(username, password)




Example 2: Using the Get Token Method through the Business Analyst Online API REST Get Token Service

Notes: This endpoint also uses SSL encryption and is secure.

Download complete source code as Visual Studio solution to immediately execute samples. (See GetTokenExamples.getTokenExample2 in source.)


Example (2) Code
C#
string tokenServiceUrl = "https://baoapi.esri.com/bawebservices/rest/authentication";

string username = "BAOAPISAMPLE"; // Substitute user name here
string password = "baoapisample"; // Substitute password here
// NOTE: These sample credentials are associated with a limited account which 
// constrains analysis to the two ZIP codes in Redlands, CA.

UriBuilder uriBuilder = new UriBuilder(tokenServiceUrl);
uriBuilder.Query = "request=getToken&username=" + username + "&password=" + password;

System.Net.WebClient webClient = new System.Net.WebClient();
string token = webClient.DownloadString(uriBuilder.Uri);

Example (2) Code
VB.NET
Dim tokenServiceUrl As String = "https://baoapi.esri.com/bawebservices/rest/authentication"

Dim username As String = "BAOAPISAMPLE"
' Substitute user name here
Dim password As String = "baoapisample"
' Substitute password here
' NOTE: These sample credentials are associated with a limited account which 
' constrains analysis to the two ZIP codes in Redlands, CA.
Dim uriBuilder As New UriBuilder(tokenServiceUrl)
uriBuilder.Query = "request=getToken&username=" & username & "&password=" & password

Dim webClient As New System.Net.WebClient()
Dim token As String = webClient.DownloadString(uriBuilder.Uri)

See Also