Forum Discussion

durgamallesh's avatar
durgamallesh
Contributor
12 years ago

REST API Authentication

Hi,

 

I went through the documents and discussions and couldn't find a solution, may be I am missing something obvious.

 

Problem:

 

I have access to our community forums and also full permissions to use the REST API. So, when I try to call the API through python, I keep receiving error code 302, user authentication failed.

 

While browsing through the forums, I understand that I need to get an SSO key for the authentication, but I am unable to get to lithium SSO client (assuming thats how I can get the key). 

 

Any help is appreciated.

 

Cheers

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi durgamallesh,

     

    are you calling the API from a standalone application or external website? As discussed here the API supports username and password log in as well as authentication using the Lithium SSO cookie. If you get a 302 error back when using those credentials, make sure that you verify that the credentials are correct - also, please check the method you are using to send these in your request - for example a POST request of "application/x-www-form-urlencoded" Content-Type.

     

    If you are using the REST API in the Studio custom components via the rest context object - then the call will be made on behalf  of the currently logged (or anonymous) session that is browsing the Lithium communities and loading the custom component.

     

    Maybe if you can provide some context on what you are trying to accomplish I can be more specific.

     

    Thanks,

    • durgamallesh's avatar
      durgamallesh
      Contributor

      Thanks paolo.

       

      Before I proceed, I want to confirm that the credentials I am using are correct. 

       

      I am calling the API from a Python program and trying to fetch some metrics for our forums.

       

      I am trying to make a GET request to the following URL and passing user.login and user.password as the parameters

      http://forums.<my company>.com/restapi/vc/authentication/sessions/login.

       

      Please note that the user.login and user.password are the credentials I use to login to our company's forums with access to use the REST API.

       

      And this is the error, I get:

       


      <?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <response status="error">
      <error code="302">
      <message>
      User authentication failed.
      </message>
      </error>
      </response>

       

      I know that I am missing something obvious, but couldn't figure it out.

       

      Thanks for taking time to respond. Much appreciated.

       

      Cheers

      • HaidongG's avatar
        HaidongG
        Lithium Alumni (Retired)

        Hi durgamallesh,

         

        1) are you calling the authenticationurl like "/restapi/vc/authentication/sessions/login?user.login=" + user + "&user.password=" + password  ?

         

        maybe your username or password contain special characters, which break the URL?

         

        2) has your community enabled SSO?

         

        if yes, you have to get the sso authorization token from the SSO provider and call "/restapi/vc/authentication/sessions/login?sso.authentication_token=" + ssoAuthTokenString;

         

        last, through it may not be related, you may want to make sure your user id has the proper right to call REST API.

  • Hi, I'm in a similar situation, and I was wondering if you found a solution to the problem yet. Thanks!