API > API > Login and use of the token

Login and use of the token

How to login

Each user is associated with a unique token, valid for 30 minutes, that certifies that the service has been authenticated.  If you have a valid token you can make calls to WSEndUser methods. After each call to any Aruba WSEndUser method the service actually checks for an invalid token for the account specified. If this does not exist, or if the token has expired, you will need to authenticate it again to get it.
In reality, the token is a substitute for password that has a temporary validity.
The APIs are authenticated with the pair username + password or username+valid token.
Getting the token for to recall the APIs is not mandatory.
The GetUserAuthenticationToken (WsCommon) and GetUserAuthenticationToken (WsEndUser) methods cannot be called with the username + token for security reasons.

The example generates an authentication token and associates it with the account indicated.
 
//IWsCommon.GetUserAuthenticationToken Method (c# .NET) 
private static void LoginToWsCommon(WsCommonClient client)
{
    //specifica le credenziali dell'account 
    client.ClientCredentials.UserName.UserName = "ARU-0000";
    client.ClientCredentials.UserName.Password = "0123456789";

    try
    {
        WsResultOfUserToken result = client.GetUserAuthenticationToken();

        if (result.Success)
        {
            //the method was successful
        }
        else
        {
            throw new Exception(result.ResultMessage);
        }
    }
    catch (MessageSecurityException msEx)
    {
        //user not authenticated  
        throw new Exception(msEx.Message);
    }
    catch (Exception ex)
    {
        //generic exception
        throw new Exception(ex.Message);
    }
}

//IWsEndUser.GetUserAuthenticationToken Method (c# .NET) 
private static void LoginToWsEndUser(WsEndUserClient client)
{
    //specifies the account login details
    client.ClientCredentials.UserName.UserName = "ARU-0000";
    client.ClientCredentials.UserName.Password = "0123456789";

    try
    {
        var result = client.GetUserAuthenticationToken();

        if (result.Success)
        {
            //the method was successful
        }
        else
        {
            throw new Exception(result.ResultMessage);
        }
    }
    catch (MessageSecurityException msEx)
    {
        //user not authenticated
        throw new Exception(msEx.Message);
    }
    catch (Exception ex)
    {
        //generic exception
        throw new Exception(ex.Message);
    }
}
//IWsCommon.loginToWsCommon Method (JAVA)
private static void loginToWsCommon(IWsCommon client) throws Exception
{    	
    //specifies the account login details
    ((BindingProvider)client).getRequestContext()
            .put(BindingProvider.USERNAME_PROPERTY, "ARU-0000");	
    ((BindingProvider)client).getRequestContext()
            .put(BindingProvider.PASSWORD_PROPERTY, "0123456789");	

    try
    {
        WsResultOfUserToken result = client.getUserAuthenticationToken();

        if (result.isSuccess())
        {
            //the method was successful
        }
        else
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (SecurityException  ex)
    {
        //user not authenticated
        throw new Exception(ex.getMessage());
    }
    catch (Exception  ex)
    {
        //generic exception
        System.out.println(ex);
    }
}

//IWsEndUser.loginToWsEndUser Method (JAVA)
private static void loginToWsEndUser(IWsEndUser client) throws Exception
{    	
    //specifies the account login details
    ((BindingProvider)client).getRequestContext()
            .put(BindingProvider.USERNAME_PROPERTY, "ARU-0000");	
    ((BindingProvider)client).getRequestContext()
            .put(BindingProvider.PASSWORD_PROPERTY, "0123456789");	

    try
    {
        WsResultOfUserToken result = client.getUserAuthenticationToken();

        if (result.isSuccess())
        {
            //the method was successful
        }
        else
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (SecurityException  ex)
    {
        //user not authenticated
        throw new Exception(ex.getMessage());
    }
    catch (Exception  ex)
    {
        //generic exception
        System.out.println(ex);
    }
}