Requesting additional permission on new sdk, but dialog shows login form - permissions

In previous android SDK, I asked new permission by calling Facebook.authorize() and it showed approving permission screen. But in SDK 3.0, when I call FacebookActivity.openSessionForPublish() , dialog always shows login form. How can I show approving permission screen?
I've set up session that has token and expiration date and its SessionState is CREATED_TOKEN_LOADED .
Is there any requirement for showing permission dialog or does Facebook.authorize() always show login form? Then please teach me right method for that.
My code is like below
public class FbConn extends FacebookActivity {
public void onCreate(Bundle savedInstanceState) {
...
if( savedInstanceState == null ) {
Session savedSession = CommonUtil.getFbSession(CustomSessionStore.getFbInfo(getApplicationContext())); //get access token and expiration date from session store and set up new session.
Session.setActiveSession(savedSession);
setSession(savedSession);
}
}
protected void onStart() {
super.onStart();
openSessionForPublish(EpisodeApplication.config.getSelectedServer().fbAppId, Constants.FB_PERMISSIONS);
}
}
Update
I've commented out these lines and permission request screen showed successfully. But I don't sure this is right way or not.
In com.facebook.LoginActivity line 62,
Utility.clearFacebookCookies(this);
In com.facebook.Session line 1202,
Utility.clearFacebookCookies(getStaticContext());

If you already have a valid session, from a previous auth flow, then if you want to request new permissions then use the Session.ReauthorizeRequest class.
Session.ReauthorizeRequest reauthRequest = new Session
.ReauthorizeRequest(this, Constants.FB_PERMISSIONS);
session.reauthorizeForPublish(reauthRequest);
This should show a permissions screen for the new permissions you're asking for instead of the login form.
However, from looking at your logic it is not clear where you're handling the first time login. If you expect to handle it in this class then I suggest using the following:
Session.openActiveSession(this, true);
This will open up a login form if there is no cached token. If there is a cached token, it will create a new Session and make it active. This will open a session with basic permissions (if the user needs to log in) or open a session with the permissions based on the cached token retrieved. You can then call the re-auth methods to ask for publish permissions. You'll want to do that in context and typically do not want to call call the auth functions back to back, i.e. log the user in, then immediately ask for publish permissions.

Related

issue with authentication in teams bot: how to keep a tab forcibly open?

We have developed a bot based on Virtual Assistant Solution Accelerator beta 0.3.
The bot is consumed through Teams, and all in azure.
We are using other services through the bot: office365 and Yammer. The user authenticate through OAuthPrompt as per Virtual assistant code.
Until recently, everything was fine. But we discovered on Tuesday morning that we have an issue for users not already logged in.
In the process of authentication, when clicking on the login button in the oauthprompt card, it opens a new tab, connect the user and show magic code. But now, this tab is closing right after displaying the code, preventing the user to copying it into teams.
If we reopen the tab right after, the code is here and working.
We tested with chrome, Firefox and edge, same result. But on mobile the tab stays open. We tested both through teams app et teams web app.
My question now: is there a way for me to keep a tab open when it's open through a card in teams (action type is openUrl).
This is likely related to this issue, specifically in that your action type is openUrl when it should be Signin, now.
Were you using the middleware in order to get it to work initially? The middleware would look something like:
// hook up onSend pipeline
turnContext.OnSendActivities(async (ctx, activities, nextSend) =>
{
foreach (var activity in activities)
{
if (activity.ChannelId != "msteams") continue;
if (activity.Attachments == null) continue;
if (!activity.Attachments.Any()) continue;
if (activity.Attachments[0].ContentType != "application/vnd.microsoft.card.signin") continue;
if (!(activity.Attachments[0].Content is SigninCard card)) continue;
if (!(card.Buttons is CardAction[] buttons)) continue;
if (!buttons.Any()) continue;
// Modify button type to openUrl as signIn is not working in teams
buttons[0].Type = ActionTypes.OpenUrl;
}
// run full pipeline
return await nextSend().ConfigureAwait(false);
});
There was an update recently that made it so you no longer need the middleware. Instead, follow these steps:
Download the newest sample
Create your Teams Bot in the App Studio Manifest Editor
Under Domains and Permissions, ensure that token.botframework.com has been added as a valid domain.
Optionally, enable Web app Single Sign-On with your appId and https://token.botframework.com/.auth/web/redirect
Click Install and start talking to your bot
If you've done substantial work to your bot and don't want to use a fresh sample, update all of your packages to 4.4.4 and I believe you can just add this to the top of your OnTurnAsync():
if (turnContext?.Activity?.Type == ActivityTypes.Invoke && turnContext.Activity.ChannelId == "msteams")
await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
else
await base.OnTurnAsync(turnContext, cancellationToken);
If that doesn't work, you can try using this:
protected override async Task OnUnrecognizedActivityTypeAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
if (turnContext?.Activity.Type == ActivityTypes.Invoke)
{
await turnContext.SendActivityAsync(
new Activity()
{
Type = ActivityTypesEx.InvokeResponse,
Value = null
});
await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
}
}
The middleware made it so the cards in Teams use Action.OpenUrl (which no longer works) instead of Action.Signin (which is what every other channel uses).
Per #SylvainBarbot, you may also need to update your packages, as discussed in this issue

How to clear Cookies in WebView?

How do you clear the cookies from a web-view in visual studio 2015.
The cookies persist through the code below and even through an application restart.
Dim cookieManager = httpBaseProtocolFilter.CookieManager
Dim cookieCollection = cookieManager.GetCookies(New Uri("https://www.example.com"))
For Each cook As HttpCookie In cookieCollection
cookieManager.DeleteCookie(cook)
Next
The title of this question does not specify the question. I see two questions of which I may have an answer for one. The question mark at the end of the following quote leads me to believe that you are wondering how to fix the fact that the next user is already logged in:
Navigate to a page and ask a user to login
Dim req As HttpRequestMessage = New HttpRequestMessage()
req.RequestUri = New Uri("https://example.com/login")
_WebView.NavigateWithHttpRequestMessage(req)
They do a process and then they close the application
Now when the next user opens the application they are already logged in?!
When the first user closes the application it is an event. Write code which resets the login state to false when the first user closes the application.
You should be able to clear the cache using WebView.ClearTemporaryWebDataAsync.. Some people have reported though that this isn't working for them.
The "old" way of handling this is adding a query string parameter, like a timestamp, to the browser. This usually allows the bypass the caching. So instead of navigating to example.com/login, you navigate to example.com/login?stamp={DateTime.Now.Ticks}

Ionic 2 app: remember user on the device

I have an Ionic App and I'd like to put a "Remember me" checkbox in the login page, so that once the user has logged in he'll be logged in forever (unless he logouts), even if he close and re-opens the application, just as the Facebook app does.
Is there a way to do that in Ionic 2?
Thanks!
You can use localstorage to save some data for your own verification/logic handling.It's html5 supported and easy to use. The downside would be it won't be secure and it might be erased by system when there's low memory or clearing of cache.
HTML(Upon button press, but u can set it to your own preference):
<button secondary (click)="addLocalStorage()">Done</button>
In your controller:
import {Storage, LocalStorage} from 'ionic-angular';
constructor(navController, local) {
this.navController = navController;
this.local = new Storage(LocalStorage);
}
addLocalStorage(){
this.local.set("didTutorial","true");
//set the doneTutorial to be true
}
Explanation:
At the constructor , we create an new localstorage object called 'local'.
To call it, we use 'this.local' and 'set' is the method to store it.
Set(Key,Value)
In the example code above, i use 'didTutorial' as the key and 'true' as the value.
To retrieve it, you can retrieve it at this page or at any other page.
Just remember to import Storage and LocalStorage and declare a new localstorage object in the constructor.(same as above)
The code to retrieve is :
var value = localStorage.getItem('didTutorial');
getitem(Key,Value)
You can use storage and sqlStorage to save user data. And then check it for saved user.
Refer :-
https://www.thepolyglotdeveloper.com/2015/12/use-sqlite-in-ionic-2-instead-of-local-storage/
Hope this helps!
localStorage works fine but I confirm the drawbacks that #Gene talks about. It is not reliable, especially on iPhones that do not have much free storage
I use ionic 1 so I cannot try this solution, but you might want to check this out : https://ionicframework.com/docs/native/native-storage/
; could be more reliable!

Fiddler Reissue and Edit and Reissue from composer

I'm using Fiddler on daily life. However, the most used feature for me, such as Reissue and Edit and Reissue from composer don't have any shortcuts. I don't know how to use fiddler script for this. Can anybody point a solution for this?
Hit CTRL+R to open the FiddlerScript editor.
Inside the OnBoot() function add the following code:
FiddlerApplication.UI.lvSessions.add_KeyDown(HandleAKey);
Immediately after the closing brace for the OnBoot function, add the following code:
static function HandleAKey(Sender, theKey:KeyEventArgs) {
if (theKey.KeyData == Keys.E)
{
var oS: Session = FiddlerApplication.UI.GetFirstSelectedSession();
if (null == oS) return;
theKey.Handled = theKey.SuppressKeyPress = true;
FiddlerApplication.DoComposeByCloning(oS);
}
}
Save the file. Restart Fiddler. Now, when you press the E key on any selected session in the Web Sessions list, that session will be cloned to the composer to resend.
Currently, the FiddlerApplication.UI.actReissueSelected() function is not public, which means that there's no simple way to invoke that functionality without calling FiddlerApplication.oProxy.SendRequest() directly.

html5 geolocation api: knowing when the user is being asked for permission and when the browser is trying to get the position

I'm wondering if the html5 geolocation api allows a way (an event or method) to tell the difference when an user is being asked for permission to share his location and when (being the permission granted) the browser is trying to get such location.
What I want to do is:
Give the user the possibility to share his location with my site.
When the user's browser asks him for permission, show the user a little help with what to do on the browser's "asking bar".
If the user grants the permission, show a little loading sign with something like "... we are trying to get your location, hang on".
This is important because:
It's always good to help out amateur users.
At least in firefox (without googlegears), takes a lot of time to get the user's position.
If the user saves his answer to that question in his preferences, there's no need to show again the help when trying to get the location.
This is what i'm doing right now is pretty straight forward:
showHelp();
navigator.geolocation.getCurrentPosition(permissionGranted, permissionDenied);
hideHelp();
But doing that i'm shoing the "help" everytime, even if the user has already granted the permissions. Also, it's a little bit awkward that, if the user was indeed asked for permission and then accepted, the "help sign" keeps showing till the browser gets the location.
Thanks for the help.
Try putting 'hideHelp' in one or both of your callbacks. see below:
$(document).ready(function () {
sample.showHelp();
navigator.geolocation.getCurrentPosition(sample.getPosSuccess, sample.getPosFail);
});
var sample = {
getPosSuccess: function () {
sample.hideHelp();
},
getPosFail: function () { alert('#fail'); },
showHelp : function () {
// your code here
},
hideHelp : function () {
// your code here
}
};