public override bool _finalizeAuthorization(string url)
        {
            string code = Utils.stringFindUrlValue(url, "code");

            if (code != null)
            {
                // trade code for access token
                string redirect_url = Utils.urlSanitizeParameter(Utils.urlTrimQuery(url), true, "domain=facebook");
                Dictionary <string, string> parameters = new Dictionary <string, string> {
                    { "client_id", AppId }, { "client_secret", AppSecret }, { "redirect_uri", redirect_url }, { "code", code }
                };
                string http_result = "";
                int    status      = _executeHttpRequest(ApiUrl + "v2.8/oauth/access_token", "POST", null, parameters, null, null, out http_result);
                string token       = Utils.stringFindJsonValue(http_result, "access_token");
                if (token != null)
                {
                    // get user account information
                    parameters = new Dictionary <string, string> {
                        { "access_token", token }, { "fields", "id,email,first_name,last_name" }
                    };
                    status = _executeHttpRequest(ApiUrl + "me", "POST", null, parameters, null, null, out http_result);
                    if (http_result != null)
                    {
                        Account = new CloudAccount(Domain, Utils.stringFindJsonValue(http_result, "id"), token, Utils.stringUtfDecode(Utils.stringFindJsonValue(http_result, "email")), Utils.stringFindJsonValue(http_result, "first_name") + " " + Utils.stringFindJsonValue(http_result, "last_name"));
                    }
                }
            }
            return(Account != null);
        }
        public override bool _finalizeAuthorization(string url)
        {
            string code = Utils.stringFindUrlValue(url, "code");

            if (code != null)
            {
                // change the code we received for an access token
                string redirect_url = Utils.urlSanitizeParameter(Utils.urlTrimQuery(url), true, "domain=dropbox");
                Dictionary <string, string> headers = new Dictionary <string, string>(_defaultHeaders);
                headers["Authorization"] = Utils.httpCalculateBasicAuthentication(AppId, AppSecret);
                Dictionary <string, string> parameters = new Dictionary <string, string> {
                    { "grant_type", "authorization_code" }, { "redirect_uri", redirect_url }, { "code", code }
                };
                string http_result = "";
                int    status      = _executeHttpRequest(ApiUrl + "oauth2/token", "POST", null, parameters, headers, null, out http_result);
                string token       = Utils.stringFindJsonValue(http_result, "access_token");
                string account_id  = Utils.stringFindJsonValue(http_result, "account_id");
                if (token != null && account_id != null)
                {
                    // replace auth header with real token
                    headers["Authorization"] = "Bearer " + token;
                    // get account info for id, name and email
                    status = _executeHttpRequest(ApiUrl + "2/users/get_account", "POST", "{\"account_id\":\"" + account_id + "\"}", null, headers, null, out http_result);
                    if (http_result != null)
                    {
                        Account = new CloudAccount(Domain, account_id, token, Utils.stringFindJsonValue(http_result, "email"), Utils.stringFindJsonValue(http_result, "display_name"));
                    }
                }
            }
            return(Account != null);
        }
        public override bool _finalizeAuthorization(string url)
        {
            string code = Utils.stringFindUrlValue(url, "code");

            if (code != null)
            {
                // first trade OAuth code for an access token
                string redirect_url = Utils.urlSanitizeParameter(Utils.urlTrimQuery(url), true, "domain=slack");
                Dictionary <string, string> parameters = new Dictionary <string, string> {
                    { "client_id", AppId }, { "client_secret", AppSecret }, { "redirect_uri", redirect_url }, { "code", code }
                };
                string http_result = "";
                int    status      = _executeHttpRequest(ApiUrl + "oauth.access", "POST", null, parameters, null, null, out http_result);
                string token       = Utils.stringFindJsonValue(http_result, "access_token");
                if (token != null)
                {
                    // then use the test service to fetch the user id
                    parameters = new Dictionary <string, string> {
                        { "token", token }
                    };
                    status = _executeHttpRequest(ApiUrl + "auth.test", "POST", null, parameters, null, null, out http_result);
                    string uid = Utils.stringFindJsonValue(http_result, "user_id");
                    if (uid != null)
                    {
                        // finally get the users name and email
                        parameters.Add("user", uid); // need token + uid
                        status = _executeHttpRequest(ApiUrl + "users.info", "POST", null, parameters, null, null, out http_result);
                        if (http_result != null)
                        {
                            string name = Utils.stringFindJsonValue(http_result, "real_name");
                            if (name == null)
                            { // user might not have given the real name, resort to screen nick
                                name = Utils.stringFindJsonValue(http_result, "name");
                            }
                            Account = new CloudAccount(Domain, uid, token, Utils.stringFindJsonValue(http_result, "email"), name);
                        }
                    }
                }
            }
            return(Account != null);
        }
        public override bool _finalizeAuthorization(string url)
        {
            string oauth_verifier = Utils.stringFindUrlValue(url, "oauth_verifier");
            string oauth_token    = Utils.stringFindUrlValue(url, "oauth_token");

            if (oauth_verifier != null && oauth_token != null)
            {
                // this time the one time token we stored/received are used in Oauth header calculation as user token/secret
                string oauth_secret = AuthorizationRequestTokens[oauth_token];
                AuthorizationRequestTokens[oauth_token] = null;
                Dictionary <string, string> headers = new Dictionary <string, string> {
                    { "Authorization", _calculateOAuth1Authorization(OAuthUrl + "access_token", "POST", null, null, Utils.stringRandomize(16), AppId, AppSecret, oauth_token, oauth_secret) }
                };
                string result = "";
                int    status = _executeHttpRequest(OAuthUrl + "access_token", "POST", null, new Dictionary <string, string> {
                    { "oauth_verifier", oauth_verifier }
                }, headers, null, out result);
                // now we got the permanent user token/secret that we can use to calculate
                string user_token  = Utils.stringFindUrlValue(result, "oauth_token");
                string user_secret = Utils.stringFindUrlValue(result, "oauth_token_secret");
                string user_id     = Utils.stringFindUrlValue(result, "user_id");
                if (user_token != null && user_secret != null && user_id != null)
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string> {
                        { "user_id", user_id }
                    };
                    headers = new Dictionary <string, string> {
                        { "Authorization", _calculateOAuth1Authorization(ApiUrl + "users/show.json", "GET", parameters, null, Utils.stringRandomize(16), AppId, AppSecret, user_token, user_secret) }
                    };
                    _executeHttpRequest(ApiUrl + "users/show.json", "GET", null, parameters, headers, null, out result);
                    if (result != null)
                    {
                        Account = new CloudAccount(Domain, Utils.stringFindJsonValue(result, "id_str"), user_id + "_" + user_token + "_" + user_secret, null, Utils.stringFindJsonValue(result, "name"));
                    }
                }
            }
            return(Account != null);
        }
 /// Constructor from an account
 ///
 /// @param CloudAccount account Account object
 ///
 public TwitterApi(CloudAccount account) : this()
 {
     Account = account;
 }
 /// Constructor from an account
 ///
 /// @param CloudAccount account Account object
 ///
 public SlackApi(CloudAccount account) : this()
 {
     Account = account;
 }
 /// Constructor from an account
 ///
 /// @param CloudAccount account Account object
 ///
 public FacebookApi(CloudAccount account) : this()
 {
     Account = account;
 }
 /// Constructor from an account
 ///
 /// @param CloudAccount account Account object
 ///
 public DropboxApi(CloudAccount account) : this()
 {
     Account = account;
 }
 /// Accounts are considered equal if same user and token (user info might have changed)
 ///
 /// @param CloudAccount account
 /// @returns Whether equal
 ///
 public bool Equals(CloudAccount account)
 {
     return(account != null && account.Id == Id && account.Token == Token);
 }