I use facebook for android sdk for SSO.
My activity calls fb.authorize() function to do OAuth. In this function I give a reference to the DialogListener object that is responsible to take proper actions depending on OAuth results. It is possible that the OS has killed the activity by the time user returns from FB App and the DialogListener Object is lost. In that case there's no way to get the AccessTokens which we were supposed to get in DialogListener.
How to handle this situation?
You can call:
mFB.getAccessToken()
But you can store the session in SharedPreferences to reuse it locally. Tokens will expire and will be requested and stored when needed again.
https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/SessionStore.java
I am answering this myself.
Facebook app after doing OAuth returns results in an intent data which we get in onActivityResult(); It is required to call mFB.authorizeCallback() in onActivityResult.
If you look into the source of this function, you will know how to extract it from the intent data. And doing that you can get access tokens in onActivityResult.
Here's the link to the source
https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/Facebook.java#L417
Related
I am trying to make sense on how to use android's AppAuth library based on the different examples that showcase different use cases of this library. I haven't managed to grasp what it requires for it to work. I also had a look at their docs
my approach:
Call the fetchFromIssuer method, this method is passed the discovery doc uri, which when called is successful. From this discovery doc, i use the authorisation endpoint and token endpoint to configure a new service like so:
val authServConfig = AuthorizationServiceConfiguration(
authEndpoint /* from discovery doc */,
tokenEndpoint /* from discovery doc */,
)
More configuration is performed, then when the intent is fired and a browser is launched to enter the details, once these details are entered and sign in is performed, I am redirected back to the app launch screen. At this point I don't know how to go about intercepting this token or whether or not the authentication was succesfull.
the code for the intent:
val authServ = AuthorizationService(applicationContext)
try {
val authIntent = authServ.getAuthorizationRequestIntent(authRequest)
startActivity(authIntent)
The intent is successful but the redirect after authenticating I don't know where it goes.
The examples I have come across with this app have invoved:
downloading an example project which when downloaded and launched using android studio, error upon error, nothing works.
I chose to work with this example but again no luck: codelabs
With AppAuth, if you have not worked with token authorisation comfortably you may find it somewhat challenging to use this library. I also have to say it does some heavy lifting and gives you some mechanisms out of the box to work with.
Configure the library as recommended or how you want to use it.
My approach so far is to have one wrapper class that will manage the instances for the Service and State (for now).
The part were I was stuck is because I was missing the RedirectUriReceiverActivity. It is this activity's intent result you get to work with in onActivityResult. It is in here you handle the response from the browser intent (After user successfully acquires a token).
Also don't forget to handle when the user chooses to dismiss the intent.
Regarding the refresh token. The library has performActionWithFreshTokens method on authsate.
I am trying to use
mLinphoneCore.clearAuthInfos()
mLinphoneCore.clearProxyConfigs();
Neither methods, but has good results.
After all, how should I cancel the registration?
I tried to successfully log out of the account on the server using the following method.
https://i.stack.imgur.com/sCfod.png
proxyCfg:This is the LinphoneProxyConfig object at login time.
name,password,host:These are the usernames, passwords, and domain names that are logged in.
Because the method used by iOS is not the same, so I am not sure if it is completely correct.
As we know, we have an api in KeyguardManager for authenticatng the user through his device lock. The api is : confirmDeviceCredentialIntent.
The doc for this api says :
Get an intent to prompt the user to confirm credentials (pin, pattern or password) for the current user of the device. The caller is expected to launch this activity using startActivityForResult(Intent, int) and check for RESULT_OK if the user successfully completes the challenge.
Now, my problem is, I want to invoke this flow in a non-activity context. I am using a kv store in my app whose contents would be encrypted by the key that I am storing in android keystore. So when I want to get any value fro that store, I first need to authenticate user so that I get my key and decrypt the content before returning.
Second thing is, I, as a consumer of that kv store, don't want to be aware about how the encryption of the store is done and therefore I shouldn't invoke confirm credentials myself. I just want my value from the store and it's store's (which is non-ui component) responsibility to invoke the authentication flow if it's required.
So mostly, I'd be using the global application context. And this context doesn't provide startActivityForResult api.
Is there any other way by which I can get result of confirm credentials action from user?
I ended up using a Dummy Activity. This activity itself is launched by application context and then it handles invoking confirmCredentials intent for result.
I call LoginManager's logout method. I see in logout() method's implementation that AccessToken was set to null, current profile is set to null, express login set to false. But what I noticed, by setting break points inside the Facebook SDK is that it wants to do a local broadcast of the token and profile having changed, but then I set a breakpoint where it should have received the broadcast and the breakpoint never trips.
I followed the instruction on how to setup the Manifest. I don't believe I've done anything incorrectly. I see a lot of old comment talking about calling FacebookSDK.SDKInitialize() but that's old documentation as sdkInitialize is deprecated and should be automatically called for you by the SDK already.
It seems that using GraphRequest to take away permssion by DELETE of /me/permission get me to the point where on next launch of the app, facebook will ask if user wants to login as . You have to go to the device's Account in Settings to delete the facebook account before it'll let you login as another user.
I'm in a situation where I need to request access tokens for two scopes (from my android application), https://www.googleapis.com/auth/userinfo.email and https://www.googleapis.com/auth/userinfo.userinfo
I would like to get both permissions on a single call to getAuthToken, but can't figure out the string to pass in the authTokenType parameter. I tried several reasonable combinations with no positive results :(
Has anyone solved this issue? Is it possible?
I was having the same issue. Shah is almost right, but his scope string is wrong. It should be
"oauth2:<scope_url> <scope_url>"
not
"oauth2:<scope_url> oauth2:<scope_url>"
If you need multiple OAuth 2.0 scopes, use a space-separated list.
oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.userinfo
You asked for sample code, so have a look at the Google Docs Upload Sample application, and in this application have look at the authentication flow done in this sample Android screen (ignore that it's about Google Docs, it still authorizes first). You can get the whole application and run it in an emulator with Google APIs present or run it on your phone. The authorization workflow starts with the buttonAuthorize click, Authorize() and you are specifically interested in this method:
private void gotAccount(Account account)
{
Bundle options = new Bundle();
accountManager.getAuthToken(
account, // Account retrieved using getAccountsByType()
"oauth2:https://www.googleapis.com/auth/userinfo.email oauth2:https://www.googleapis.com/auth/userinfo.userinfo", // Auth scope
//"writely", // Auth scope, doesn't work :(
options, // Authenticator-specific options
this, // Your activity
new OnTokenAcquired(), // Callback called when a token is successfully acquired
null); // Callback called if an error occurs
}
The user gets this access request screen:
Note that this is using the 'local' OAuth2 mechanism, not opening a web browser, but using the authentication provided when you first activated the Android phone.
Also note that the user sees the full URL of the scope instead of a friendly name, I haven't found a way around this and if you do find out it would be great if you could share the answer.