How does the GitHub android application use authentication?

I am going through the source code of an Android app from GitHub .

I am trying to figure out how they make LoginActivity appear when I first run the application. In their manifest, they seem to have HomeActivity as MAIN and LoginActivity starts explicitly .

Thus, this means that HomeActivity always starts when you first open the application. However, I do not see any logic in HomeActivity that shows that they check for the presence or absence of an account, if it is not, go to LoginActivity

In the code, LoginActivity is called.

+6
source share
2 answers

Well, the whole Android account authentication and synchronization mechanism can be quite complicated at a glance, and the GitHub app for Android adds another level of complexity, but I will try to explain the whole stream to you (I hope that my understanding is correct).

First, I recommend this article about Android Authenticator if you are not already familiar with the subject. GitHub Android uses exactly the same mechanism described in this article.

You are right, HomeActivity starts HomeActivity . He then starts OrganizationLoader to load the list of orgs. This loader calls a method from OrganizationService , which is part of the Java GitHub API . GitHub Android uses RoboGuice to configure the injection of the most commonly used classes, such as the GitHub API services. You can see that the OrganizationService is created in the ServicesModule . A constructor parameter requires GithubClient , as well as a GitHubModule , which is configured to return an AccountClient when an instance of GithubClient . AccountClient overrides the configureRequest() method and calls

String token = account.getAuthToken();

This is a method of the GitHubAccount class that calls a method from the internal Android AccountManager . And the AccountManager configured to use this AccountAuthenticator , which you mentioned, which returns the LoginActivity intention if the device does not have an account.

Hope this helps :)

+6
source

The application uses the Android account system, which is actually implemented in the class that you have already found. This accounting system at some point will call getAuthToken() , and there will be a simple check whether the password is empty , which returns the Intent for LoginActivity to the account management system. Using this intention, the account management system will return to the application and finally call the LoginActivity function.

+2
source

All Articles