$show=home$hide=mobile-page

HP ALM REST API - Authentication

Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources.

Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources
Contents of this post
  • Introduction to ALM Authentication Resource 
  • Explanation on Sign-in resource 
  • Sign-in codes
    • VB Code for Sign-in
    • C# Code for Sign-in
  • Explanation on Sign-out resource
  • Sign-out codes
    • VB Code for Sign-out
    • C# Code for Sign-out

HP ALM provides two resources for Authentication.
  • Sign-in
  • Sign-out

Sign-in

The sign-in resource request authorization. To sucessfully authenticate we have to post user and password in BASE64 encoding in the Authorization header.

Sign-in resource sets the authentication cookies required for future requests.
  • ALM_USER
  • LWSSO_COOKIE_KEY
  • QCSession
  • XSRF-TOKEN

Sign-in URI

Uri for sign-in is /qcbin/api/authentication/sign-in
e.g. http://youralmserver:port/qcbin/api/authentication/sign-in

  •  
  • For ALM Versions prior to 12.53

    Uri for sign-in is /qcbin/authentication-point/authenticate?login-form-required=y
    e.g. http://youralmserver:port/qcbin/authentication-point/authenticate?login-form-required=y

    If this URI is provided directly to browser, you will get a prompt to enter your user name and password. Once you enter the correct credentials you will be taken to a blank screen.

    [post_ads]

    Doing it with code

    Inputs Required
    Prameter Example
    HP ALM Base URL http://youralmurl:port/qcbin
    HP ALM User Name aneejian
    HP ALM Password Password
    Sample Response

    ****  Request ***
    POST /qcbin/api/authentication/sign-in HTTP/1.1
    Authorization: Basic 123456789abcdef=
    Host: myserver:8081
    
    ****  Response ***
    HTTP/1.1 200 OK
    Set-Cookie: LWSSO_COOKIE_KEY=0123456789abcdef;Path=/;HTTPOnly
    Set-Cookie: QCSession=0123456789abcdef;Path=/;HttpOnly
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Set-Cookie: ALM_USER=0123456789abcdef;Path=/
    Set-Cookie: XSRF-TOKEN=0123456789abcdef;Path=/
    Content-Length: 0

    Sign-in Code

    VB Code to get Authentication Cookies

    Private Function GetAuthenticationCookieContainer(almBaseUrl, almUserName, almPassword) As CookieContainer
     Dim authCookies = new CookieContainer()
     Dim auth As HttpWebRequest = WebRequest.Create(almBaseUrl + "/api/authentication/sign-in")
     Dim credentials As String = $"{almUserName}:{almPassword}"
     auth.CookieContainer = authCookies
     auth.Headers.Set(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)))
     Dim authResult As WebResponse = auth.GetResponse()
     Return authCookies
    End Function

    Usage

    Dim AuthenticationCookieContainer = GetAuthenticationCookieContainer("http://youralmurl:port/qcbin", "aneejian", "Password")

    C# Code to get Authentication Cookies

    private static CookieContainer GetAuthenticationCookie(string almBaseUrl, string almUserName, string almPassword)
    {
        var authCookies = new CookieContainer();
        var auth = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/authentication/sign-in");
        var credentials = $"{almUserName}:{almPassword}";
        auth.CookieContainer = authCookies;
        auth.Headers.Set(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
        var authResult = auth.GetResponse();
        return authCookies;
    }

    Usage

    var authenticationCookieContainer = GetAuthenticationCookie("http://youralmurl:port/qcbin", "aneejian", "Password");
  •  
  • For ALM Versions prior to 12.53
    In the code replace /api/authentication/sign-in with /authentication-point/authenticate
    [post_ads_2]

    Sign-out

    The sign-out resource logs the user off the system. It cancels the cookies returned by Sign-in.
    • LWSSO_COOKIE_KEY
    • QCSession 
    • ALM_USER 
    • XSRF-TOKEN

    Sign-out URI

    Uri for sign-out is /qcbin/api/authentication/sign-out
    e.g. http://youralmserver:port/qcbin/api/authentication/sign-out

  •  
  • For ALM Versions prior to 12.53

    Uri for sign-out is /qcbin/authentication-point/logout
    e.g. http://youralmserver:port/qcbin/authentication-point/logout
    If you pass this to the browser where you signed in, it will sign you out from ALM.

    Sign-out Code

    VB Code to Sign-out

    Private Sub Signout(almBaseUrl As String, AuthenticationCookieContainer)
     Dim auth = CType(WebRequest.Create(almBaseUrl + "/api/authentication/sign-out"), HttpWebRequest)
     auth.CookieContainer = AuthenticationCookieContainer
     Dim authResult = auth.GetResponse()
    End Sub

    Usage

    SignOut("http://youralmurl:port/qcbin", AuthenticationCookieContainer)

    C# Code to Sign-out

    private static void SignOut(string almBaseUrl, CookieContainer authenticationCookieContainer)
    {
     var auth = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/authentication/sign-out");
     auth.CookieContainer = authenticationCookieContainer; //authenticationCookieContainer is the CookieContainer you got from GetAuthenticationCookieContainer function.
     var authResult = auth.GetResponse();
    }

    Usage

    SignOut("http://youralmurl:port/qcbin", authenticationCookieContainer);
  •  
  • For ALM Versions prior to 12.53
    In the code replace /authentication/sign-out with /authentication-point/logout

    COMMENTS





    Name

    AngularJS,3,Automation Testing,8,CSharp,5,Disqus,1,Excel,2,HP ALM,5,HTML5,1,ISTQB,2,Java Script,2,Manual Testing,7,Photography,1,Quiz,2,REST API,5,Testing,15,UFT,8,VB,5,VBScript,1,Wordpress,1,
    ltr
    item
    Aneejian: HP ALM REST API - Authentication
    HP ALM REST API - Authentication
    Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources.
    https://1.bp.blogspot.com/-T3UvS9Ke48M/WNAnQkGI7YI/AAAAAAAAAK8/43r6HQEAuy0ovkzeeh9RFLaagmW3emfJgCLcB/s320/restapiauthentication.jpg
    https://1.bp.blogspot.com/-T3UvS9Ke48M/WNAnQkGI7YI/AAAAAAAAAK8/43r6HQEAuy0ovkzeeh9RFLaagmW3emfJgCLcB/s72-c/restapiauthentication.jpg
    Aneejian
    http://www.aneejian.com/2017/03/hp-alm-rest-api-authentication.html
    http://www.aneejian.com/
    http://www.aneejian.com/
    http://www.aneejian.com/2017/03/hp-alm-rest-api-authentication.html
    true
    5798203121010168414
    UTF-8
    Loaded All Posts No posts found VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU ARCHIVE SEARCH ALL POSTS No post found which matches with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy