Authenticating with a GraphQL API: Obtaining access tokens via various methods

Hey folks, I’m struggling to access a CRM system’s backend via API calls. The system uses Symphony and AngularJS, with most of the frontend running on GraphQL in version 8.x. I’ve been trying to replicate the login process I see in my browser’s network tab, but I’m hitting a wall.

When I attempt to log in using Postman, I get a 401 error saying ‘Invalid CSRF token.’ This has me puzzled. Do I need a token just to log in? Is it some kind of session thing?

I’ve noticed some cookies in my browser during the login process. Are these the tokens I need to use in Postman? But how does the login request get these cookies if it’s the first page load?

I’ve also explored using Authorization with a bearer token in Postman, but I’m not sure if that’s the right approach or where to obtain the token from.

I’ve tried n8n and Python as well, but no luck so far. There’s zero documentation on this matter, which makes troubleshooting quite challenging.

Has anyone encountered a similar issue? Any advice on how to authenticate and retrieve tokens for a GraphQL API would be greatly appreciated. Thanks!

I’ve dealt with similar authentication challenges in GraphQL APIs before. For the CSRF token issue, you might need to make an initial request to get the token before attempting to log in. Some systems set this as a cookie or include it in the response headers. Regarding cookies, they’re often set after a successful login. However, some systems use a two-step process: first, you get a session cookie, then use that for login. For bearer tokens, these are typically obtained after a successful login. You’d use the login credentials to get the token, then use the token for subsequent requests. Have you tried inspecting the login request in your browser’s dev tools? Look at the request headers, payload, and response. This can give clues about what the API expects. Also, check if there’s an OPTIONS request before the login - it might reveal required headers. If all else fails, you might need to reverse engineer the frontend code to see how it’s handling authentication. It’s tedious, but sometimes necessary when dealing with undocumented APIs.

hey there! i’ve run into similar headaches before. sounds like u might need to snag that CSRF token first before trying to log in. check the network tab for any requests that might be setting it. for the bearer token, usually u gotta login successfully first to get it. have u tried mimicking the exact headers and payload from the browsers login request in postman? that could help. good luck!

Ah, GraphQL authentication can be a real pain sometimes! I’ve been there, trust me. From what you’re describing, it sounds like you’re dealing with a multi-step auth process. Here’s what I’d suggest:

First, try to capture the entire login flow in your browser’s network tab. Look for any initial requests that might be setting up the session or grabbing that pesky CSRF token.

For the 401 error in Postman, you might need to make a preliminary request to get the CSRF token, then include it in your login attempt. Some systems use this as a security measure.

As for the bearer token, that’s typically what you get after a successful login. You’d use your credentials to obtain it, then use the token for subsequent API calls.

Have you considered using a tool like Charles Proxy or Fiddler to intercept and analyze the traffic between your browser and the API? This can give you a clearer picture of what’s happening under the hood.

Lastly, don’t underestimate the power of trial and error. Sometimes, you just have to keep tweaking your requests until you crack the code. It’s frustrating, but often the only way with undocumented APIs.

Keep at it, and don’t hesitate to ask for more help if you need it!