public void LoginWithTwitter(Microsoft.Phone.Controls.WebBrowser webBrowser, IDictionary <string, string> twitterFieldsMappings, AsyncCallback <BackendlessUser> callback) { try { if (webBrowser == null) { throw new ArgumentNullException(ExceptionMessage.NUL_WEBBROWSER); } Invoker.InvokeAsync(USER_MANAGER_SERVER_ALIAS, "getTwitterServiceAuthorizationUrlLink", new Object[] { Backendless.AppId, Backendless.VersionNum, HeadersManager.GetInstance().Headers[HeadersEnum.APP_TYPE_NAME.Header], twitterFieldsMappings }, GetSocialEasyLoginAsyncHandler(webBrowser, callback)); } catch (System.Exception ex) { if (callback != null) { callback.ErrorHandler.Invoke(new BackendlessFault(ex.Message)); } else { throw; } } }
protected async Task AuthorizeOAuthTokens() { //Debug.WriteLine("In AuthorizeOAuthToken function"); HttpClient tweetClient = new HttpClient(); string authorizeRequestUrl, authorizeResponse; Uri requestUri, callbackUri; Microsoft.Phone.Controls.WebBrowser AuthPageBrowser = _authWebControl as Microsoft.Phone.Controls.WebBrowser; //HttpResponseMessage authResponse; //HttpRequestMessage authRequest //"https://api.twitter.com/oauth/authorize?oauth_token=" + oauth_token; authorizeRequestUrl = TweetAuthConstants.AuthorizeURL + "?" + OAuth.OAuthTypes.OAuthTokenString + OAuth.OAuthTypes.OAuthRequestTokenKey; authorizeRequestUrl += "&redirect_uri=" + OAuth.OAuthTypes.OAuthCallbackKey; requestUri = new Uri(authorizeRequestUrl, UriKind.Absolute); callbackUri = new Uri(OAuth.OAuthTypes.OAuthCallbackKey); System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { //change UI here AuthPageBrowser.Navigate(requestUri); }); //Debug.WriteLine("Navigating to: " + authorizeRequestUrl); // //DebugPrint("Navigating to: " + TwitterUrl); //WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync( //WebAuthenticationOptions.None, //requestUri, //callbackUri); //if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) //{ // //Debug.WriteLine("Access Tokens Acquired, User Authorized and AuthenicatedUser is " + this.AuthenticatedUser); // authorizeResponse = webAuthenticationResult.ResponseData.ToString(); // Dictionary<string, string> authData = authorizeResponse.Split('?').ToList()[1].Split('&').Select(p => p.Split('=')).ToDictionary(param => param[0], param => param[1]); // OAuth.OAuthTypes.OAuthAccessTokenKey = authData["oauth_token"]; // OAuth.OAuthTypes.OAuthVerifierKey = authData["oauth_verifier"]; //} //else //{ // this.AuthenticatedUser = false; //Debug.WriteLine("User Not Authorized, In Tweet OAuth and AuthenicatedUser is " + this.AuthenticatedUser); // throw new Exception(webAuthenticationResult.ResponseErrorDetail.ToString()); //} }
public static void GetUserAgent(Panel rootElement, Action <string> callback) { var browser = new Microsoft.Phone.Controls.WebBrowser(); browser.IsScriptEnabled = true; browser.Visibility = Visibility.Collapsed; browser.Loaded += (sender, args) => browser.NavigateToString(Html); browser.ScriptNotify += (sender, args) => { string userAgent = args.Value; rootElement.Children.Remove(browser); callback(userAgent); }; rootElement.Children.Add(browser); }
private AsyncCallback <string> GetSocialEasyLoginAsyncHandler(Microsoft.Phone.Controls.WebBrowser webBrowser, AsyncCallback <BackendlessUser> callback) { return(new AsyncCallback <string>( response => Deployment.Current.Dispatcher.BeginInvoke(() => { var uri = new Uri(response, UriKind.Absolute); webBrowser.IsScriptEnabled = true; webBrowser.ScriptNotify += (sender, args) => { var result = (new Utils.Json()).Deserialize(args.Value); GetUserLoginAsyncHandler(callback, false).ResponseHandler.Invoke(result); }; webBrowser.Navigate(uri); }), fault => { if (callback != null) { callback.ErrorHandler.Invoke(fault); } })); }