REST Api Authentication Issues

Hi all,

I have been trying to authenticate users using the GitHub API Im using .net core as my app and the first part of the authentication works fine and redirects to my app but when I try to exchange the temporary code for a token I always get invalid credentials


error. I have checked the values on the parameter and the client id, secret and code are all ok? Anyone any ideas?

That is what we send in our Git X Modules App https://gitx.dev:

BodyInserters
.fromFormData("client_id", oauth2Properties.getClientId())
                .with("client_secret", oauth2Properties.getClientSecret())
                .with("code", code)
                .with("state", state)
                .with("grant_type", "authorization_code")
                .with("redirect_uri", appRedirectUri)

So, in your example “grant_type”, “redirect_uri” and “state” values are missing (state is passed as redirect query parameter). Also, I would recommend to enable logging and check that all values that you send are correct.

Hi,

This is interesting. So I was keeping it dead simple, only using the required fields, The first stage seems to work but the second stage seems to throw that invalid credentials error. Im using the Web Application flow guide from github. I tried logging it and it all seems fine…

You may check this page https://docs.github.com/en/developers/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors

It says that invalid client credentials error is reported when client id or secret are not valid.

I am not familiar with .net APIs, but would suggest to check also Content-Type request header value you set for the token request. In our code it is set to “application/x-www-form-urlencoded”, also Accept header is set to “application/json”

Hope that helps.