OAuth2 with manual step

I’m trying to configure a http request node with oauth2 authentication. The problem is that this particular oauth2 authentication redirects to a login page in which you must manually login before you get your first access and refresh tokens. Is there a way to use the oauth2 functionality by skipping the first part and entering a refresh token directly? The refresh token is used to request an new access and refresh token and will never expire except when a new refresh token was requested.

Hey @Daomenis!

Welcome to the community :sparkling_heart:

What you described is how the OAuth2 authentication works. You have to set your credentials, and to give access you need to log in. Once you’re login, the service (the one whose API you’re using), will send the tokens to the redirect URL. You can then make the HTTP calls.

You can’t bypass the first step. If you really want to do that, you will have to look at how the request is made with the token and replicate it in the node. For example, if the token is sent in the Headers, you can add it as a header in the HTTP Request node. However, this is not recommended due to security reasons.

Oh I see, for some reason I thought the normal way was to post credentials instead of login screen. I just tried to set it up in n8n and it worked immediately, looks great! Thank you for taking the time to let me know!

OAuth2 has different grant types. n8n implements the authorization code one. What you are looking for seems to be the refresh token grant type.

https://oauth.net/2/grant-types/

Both the description of the authorization code and refresh token types seem to be true here. In any case it works now. Maybe it’s normal that after using authorization code, you can use refresh token to get a new access token when it expires?

I have one more quick question; when the authentication of an api is done through posting a username and password, which authentication type do I use in n8n?

If you’re using a username and password for authentication, you should use the Basic Auth method. I would also suggest you go through the documentation of the API you’re using. Sometimes they ask you to pass them in headers. In that case, you should use the Header Auth.

It’s username and password posted with specific post body data to request a token.

Then set authentication to none and add the credentials in the body.

Thank you!