Common > Login and use of the token

    1.5 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.

    //IWsEndUser.GetUserAuthenticationToken Method (c# .NET) 
    private static void LoginToAccount(WsEndUserClient client)
    {
        //specifies the account login details
        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 (JAVA)
    private static void LoginToAccount(IWsEndUser client) throws Exception
    {    	
        try
        {
            //specifies the account login details 
            ((BindingProvider)client).getRequestContext()
                    .put(BindingProvider.USERNAME_PROPERTY, "ARU-0000");	
            ((BindingProvider)client).getRequestContext()
                    .put(BindingProvider.PASSWORD_PROPERTY, "0123456789");	
    
            WsResultOfUserToken result = client.getUserAuthenticationToken();
    
            if (result.isSuccess())
            {
                //the method was successful
            }
            else
            {
                throw new Exception(result.getResultMessage());
            }
        }
        catch (SecurityException  ex)
        {
            //generic exception 
            System.out.println(ex);
        }
    }
    

    See also