Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Services need a way to delete and deauthorize accounts #5

Open
praeclarum opened this issue Mar 17, 2013 · 1 comment
Open

Services need a way to delete and deauthorize accounts #5

praeclarum opened this issue Mar 17, 2013 · 1 comment

Comments

@praeclarum
Copy link
Contributor

If an account goes bad, then we need a way to delete them from the account store.

    public static void DeleteAccount (this FacebookService facebook, Account account)
    {
        var acs = AccountStore.Create ();
        //          acs.Delete (account);
    }

    public static async Task<bool> DeauthorizeAccount (this FacebookService facebook, Account account)
    {
        var acs = AccountStore.Create ();
        acs.Delete (account);

        var req = facebook.CreateRequest (
            "DELETE",
            new Uri ("https://graph.facebook.com/me/permissions"),
            account);
        using (var resp = await req.GetResponseAsync ()) {
            return (bool)JsonValue.Parse (resp.GetResponseText ());
        }
    }
@johnbeans
Copy link

If you also have the Xamarin.Auth component, you can delete it yourself.
I have done it like this in a Xamarin.Forms app:

            var theChangeAccountButton = new Button {
                TextColor = Color.White,
                Font = Font.OfSize (textFont, textSize),
                Text = "Change account",
                BackgroundColor = Color.Transparent,
            };
            string flickrUser ="";
            if (accounts.Count () > 0) {
                flickrUser = accounts.First ().Username;
                theChangeAccountButton.Text = "Logout of " + flickrUser;
            } else {
                theChangeAccountButton.IsVisible = false;
            }
            theChangeAccountButton.Clicked +=  (sender, e) => {
                var store = AccountStore.Create ();
                IEnumerable<Account> accounts = store.FindAccountsForService ("Flickr");
                Console.WriteLine("Number of flickr accounts before is " + accounts.Count().ToString());
                Account thisAccount;
                if(accounts.Count() > 0){
                    for(int i=0;i<accounts.Count();i++){
                        thisAccount = accounts.First();
                        store.Delete(thisAccount,"Flickr");
                    }
                }
                accounts = store.FindAccountsForService ("Flickr");
                Console.WriteLine("Number of flickr accounts afterwards is " + accounts.Count());
                if(accounts.Count() == 0){
                    theChangeAccountButton.IsVisible = false;
                    DisplayAlert("Flickr","You are logged out of "+flickrUser+".","OK");
                }else{
                    DisplayAlert("Flickr","For some reason, that didn't work.","OK");
                    flickrUser = accounts.First ().Username;
                    theChangeAccountButton.Text = "Logout of " + flickrUser;
                }

            };

When there are no flickr users saved, the button is hidden. When there is at least one, the button shows "Logout of user@domain.com". Normally, there's just one, so handling multiple flickr accounts is just for robustness.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants