

For this, we need to send a login request to the authorizations endpoint: private static final String GIT_HUB_API = "" private static final String AUTHORIZATIONS_ENDPOINT = "authorizations" Uri.Builder builder = new Uri.Builder() builder.scheme("https"). Technically speaking that’s all we need to access their repos list, but if we want to do more than that we need to acquire an authorization token from GitHub. Since we’ve returned this we ask the user for their 2FA password. So to detect that we add the following in our try block in doInBackground : if (de() = 401 & ntains("Must specify two-factor authentication OTP code.")) return ERROR_2FA

Please note, however, that SMS 2FA for GitHub is finicky and might not work at all in some countries! At that point, if SMS 2FA is active, the platform should send out a OTP SMS to the user containing the code.

The process itself isn’t too complicated once you understand how it works, which is like this: if 2FA is active, when you try to log in using basic authentication the API returns a 401 response and the error message Must specify two-factor authentication OTP code. This is where things get a bit more complex. Getting Private Repos (Two Factor Authentication - OAuth2 Token) As you can see, not much changes, we simply change the endpoint and add that authorization header.
