Use State Param

Use state parameter to avoid CSRF attacks

In OAuth, the state parameter is used as a security measure to prevent CSRF (Cross-Site Request Forgery) attacks. CSRF attacks occur when a malicious website or script sends a request to a legitimate website on behalf of a user who is currently authenticated.

To prevent CSRF attacks, the state parameter is used to store a unique value that is generated by the client application before initiating the authorization request. This value is included in the authorization request and then verified by the authorization server when the user is redirected back to the client application. If the state value in the authorization response matches the state value that was sent by the client application, the authorization is considered valid and the access token is returned to the client.

By using the state parameter, you can help to prevent malicious actors from intercepting or modifying the authorization request in transit, as the unique state value is only known to the client application and the authorization server. This can help to ensure the integrity and security of the OAuth flow and protect against CSRF attacks.