Forum Discussion

4 Replies

  • Session key authentication with GraphQL is typically handled at the transport layer generate a session token after login, store it securely (cookie or header), and validate it on each request via middleware or resolvers.

  • HussnainI's avatar
    HussnainI
    Khoros Staff
    1 month ago

    Hey beefjorgensen,

    Pass the session key as an HTTP header named `li-api-session-key`.

    Example:

    curl -X POST 'https://your-community.com/api/2.1/graphql' \ 
    -H 'Content-Type: application/json' \ 
    -H 'li-api-session-key: YOUR_SESSION_KEY_HERE' \ 
    -d '{ "query": "query MessageSearch($searchTerm: String!) 
    { messageSearch(searchTerm: $searchTerm, first: 10) 
    { results { edges { node { ... on TopLevelMessageSearchResult { message { id subject } } } } } } }", 
    "variables": {"searchTerm": "your search term"} }'

    To obtain a session key:

    POST /restapi/vc/authentication/sessions/login?restapi.response_format=json.v3

    Content-Type: application/x-www-form-urlencoded

    user.login=username&user.password=password

    Example:

    curl -s -X POST 'https://<your-community>.com/restapi/vc/authentication/sessions/login?restapi.response_format=json.v3' \ 
    -H 'Content-Type: application/x-www-form-urlencoded' \ 
    -d 'user.login=$USERNAME&user.password=$PASSWORD' 
    
    Response: { "response": { "status": "success", "value": { "$": "your-session-key-here" } } }

    The session key will be in the response at `response.value.$`.

    Please ping me if you have more questions.

  • MattV's avatar
    MattV
    Khoros Staff
    9 months ago

    For now, authentication is still done with the APIv1 authentication mechanisms.