c# - Facebook re-authentication in a popup window -


i write windows forms application connects user's profile in facebook, reads wall , shows him updates in widget, of facebook c# sdk.

everything works fine, except fact facebook won't let user change credentials, means re-login different user.

my authentication flow schematically follows:

in login process initializer:

note: dialog shown in popup. if show dialog in full browser, it's possible logout, in popup functionality seems lacking.

private void loginbutton_click(object sender, eventargs e){          browser = new webbrowser();     this.browser.navigated += new webbrowsernavigatedeventhandler(browser_navigated);     //+ types of gui settings borwser     form.controls.add(browser);      uri url=new uri("https://www.facebook.com/dialog/oauth?client_id=" + {*myappsid*}+       "&redirect_uri=" + "https://www.facebook.com/connect/login_success.html" +       "&response_type=token"+       "&auth_type=reauthenticate"+       "&display=popup"+       "&scope=read_stream"      browser.navigate(url);// +try/catches - omitted } 

navigation response parsing:

note: parsing response use of c# sdk classes facebookoauthresult , facebookclient

private void browser_navigated(object sender, webbrowsernavigatedeventargs e){     facebookoauthresult oauthresult; //helps streamline parsing     if (fb.tryparseoauthcallbackurl(e.url, out oauthresult)){ //type of fb facebookclient of c# sdk         if (oauthresult.issuccess){             accesstoken = oauthresult.accesstoken;             //from here start reaing user's feed of access token         }     } } 

what meant when login button clicked, user prompted username , password.

however, user prompted re-enter password only, not re-enter username.

if use url without "&auth_type=reauthenticate" parameter , doesn't prompt , straight sends me access token.

how can force facebook ask username?

after days of fighting, answer under nose.

you need call https://www.facebook.com/logout.php access token:

        webbrowser browser = new webbrowser();         browser.navigated += browser_navigatedlogout;          string logouturl = "https://www.facebook.com/logout.php?" +             "next=https://www.facebook.com/connect/login_success.html" +             "&access_token=" + myaccesstoken;           try         {             browser.navigate(new uri(logouturl));         }         catch (system.exception other)         {             messagebox.show("error logging out: "+other.message);         } 

and handler is:

    private void browser_navigatedlogout(object sender, webbrowsernavigatedeventargs e)     {         if (e.url.absoluteuri == "https://www.facebook.com/connect/login_success.html")         {            //here need after user logged off         }     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -