Forum Discussion

MasterTesh's avatar
MasterTesh
Occasional Contributor
2 years ago

cookies authentication

Hi everyone hope you are doing well,

I would like to achieve as below in c#, but I have no idea how to do it

  1. paths:
  2. /login:
  3. post:
  4. summary: Logs in and returns the authentication cookie
  5. requestBody:
  6. required: true
  7. description: A JSON object containing the login and password.
  8. content:
  9. application/JSON:
  10. schema:
  11. $ref: '#/components/schemas/LoginRequest'
  12. security: [] # no authentication
  13. responses:
  14. '200':
  15. description: >
  16. Successfully authenticated.
  17. The session ID is returned in a cookie named `JSESSIONID`. You need to include this cookie in subsequent requests.
  18. headers:
  19. Set-Cookie:
  20. schema:
  21. type: string
  22. example: JSESSIONID=abcde12345; Path=/; HttpOnly

13 Replies

  • chichepo's avatar
    chichepo
    Champion Level 3

    Hi MasterTesh 

    Have you tried the Client or server stub generator?



    Is that what you are looking for?

  • MasterTesh's avatar
    MasterTesh
    Occasional Contributor

    yes, that's basically  what I am trying to achieve,

     
    I am posting to an API data every two hours

     

    the POST method only works with cookies, I wanna be able to capture cookies to use it with my API POST method in csharp-donet2

    • chichepo's avatar
      chichepo
      Champion Level 3

      So you mean you are the client and pointing to this endpoint?

  • MasterTesh's avatar
    MasterTesh
    Occasional Contributor

    I could not really figure it out, not sure what I doing wrong 

    Will u please assist me

    • chichepo's avatar
      chichepo
      Champion Level 3

      - Log in SwaggerHub online (Free account)
      - upload your Swagger file under your account
      - In the upper right corner, press on Export -> Server Stub (or Client SDK)
      - Choose your target language (C#, etc..)

      You will get a draft project that should be modiifed according to your needs

  • MasterTesh's avatar
    MasterTesh
    Occasional Contributor

    Hi,

    I did try that but I am getting this error

    undocumented Failed to fetch.

    Possible Reasons:

    1. - CORS
    2. - Network Failure
    3. - URL scheme must be "http" or "https" for CORS request.
    • chichepo's avatar
      chichepo
      Champion Level 3

      Look at server clause
      Can you use https instead http
      if not try to use a local mockup server in integration tab:

       ==>  
      - Put whatever as a name
      - Press on Save and Run
      - It will add a Dummy server within the server clause in your file
      - remove other server names

      it should generate successfully 

       

       

      • MasterTesh's avatar
        MasterTesh
        Occasional Contributor

        hi chechepo
        I tried so hard, it was not successful

        can I maybe share with u a temporary link, with username and password (to generate to cookies) so I see how you do it
        clearly I wasn't able to do that

        PLease