/// <summary> /// 拼接链接,跳转获取oauth token的地址 /// </summary> /// <param name="returnUrl"></param> /// <returns></returns> public ActionResult GetOAuthToken(string returnUrl) { var guid = Guid.NewGuid().ToString(); returnUrl = HttpUtility.UrlEncode(returnUrl); var callbackUrl = WechatSetting.host + Url.Action("WechatOAuthCallback", "Wechat", new { url = returnUrl }); var wechatUrl = new OAuthAPI().GetAuthorizeUrl(WechatSetting.appId, callbackUrl, guid, OAuthScope.snsapi_base); return(Redirect(wechatUrl)); }
private PublicAPIConnection PreparePublicApiConnection(string contentTypeHeaderValue) { var connection = new PublicAPIConnection(); var code = new OAuthAPI().GetCodeSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "code_direct").Code; var token = new TokenAPI().AccessTokenSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "oauth_code", AuthenticationInfoProvider.Current.DefaultAppSecret, code).AccessToken; connection.Authentication.Token = token; connection.Headers["Content-Type"] = contentTypeHeaderValue; return(connection); }
private void Reset() { ToggleButtons(true); //get empty set of credentials m_oaCredentials = OAuthAPI.GetCredentials("", ""); m_aaStatus = (AddAccountStatus)0; UpdateFromStatus(); txtPin.Text = ""; txtUrl.Text = ""; }
public void TestAuthenticationAPIs() { OAuthAPI api = new OAuthAPI(); TokenAPI tokenApi = new TokenAPI(); Authentication authentication = api.GetCodeSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "code_direct"); Assert.That(authentication, Is.Not.Null, "Cannot access to OAuth API"); authentication = tokenApi.AccessTokenSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "oauth_code", AuthenticationInfoProvider.Current.DefaultAppSecret, authentication.Code); Assert.That(authentication, Is.Not.Null, "Cannot access to Token API"); Assert.That(authentication.Error, Is.EqualTo(Enums.PublicAPIResultCode.Success.ToString()), "Getting token is not successful!"); Assert.That(authentication.AccessToken, Is.Not.Null.And.Not.Empty, "AccessToken is null or empty"); }
public IActionResult SaveGoogleAccount(OAuthLogin oauthLogin) { var record = LoginAPI.CheckUserExists(oauthLogin.Email, _clientBaseAddress.BaseURLApi); if (record == null) { var response = OAuthAPI.GenerateToken(_clientBaseAddress.BaseURLApi); oauthLogin.Token = response.access_token; LoginAPI.SaveCredentials(oauthLogin, _clientBaseAddress.BaseURLApi); } return(RedirectToAction("Index", "AdAccounts")); }
static async void CallTokenApi() { var oauthApi = new OAuthAPI(); var Response = await oauthApi.GenerateToken(); if (Response.StatusCode == HttpStatusCode.OK) { Console.WriteLine(await Response.Content.ReadAsStringAsync()); } else { Console.WriteLine("Error while fetching data."); } }
public FrmAddAccount() { InitializeComponent(); m_oaApi = new OAuthAPI(); m_alStatusPanels = new List <Panel>(); m_alStatusPanels.Add(pnlWelcome); m_alStatusPanels.Add(pnlUrl); m_alStatusPanels.Add(pnlPin); m_alStatusPanels.Add(pnlDone); m_oaApi.RequestTokenReceived += new OAuthAPI.OAuthCallbackHandler(m_oaApi_RequestTokenReceived); m_oaApi.AccessTokenReceived += new OAuthAPI.OAuthCallbackHandler(m_oaApi_AccessTokenReceived); }
public void InitHelpers(ApplicationType appType) { var appInfo = GetDefaultApplication(appType); oAuthAPI = new OAuthAPI() { AccessHelper = new PublicAPIConnection(appInfo.Key, appInfo.Secret) { IsAutoRefreshToken = false } }; tokenAPI = new TokenAPI() { AccessHelper = oAuthAPI.AccessHelper }; }
public void InitApiHelpers(ApplicationType appType) { Log.Info("Starting the test of Oauth!"); var appInfo = GetDefaultApplication(appType); oAuthAPI = new OAuthAPI() { AccessHelper = new PublicAPIConnection(appInfo.Key, appInfo.Secret) { IsAutoRefreshToken = false } }; tokenAPI = new TokenAPI() { AccessHelper = oAuthAPI.AccessHelper }; }
/// <summary> /// 获取oauth token后的回调函数 /// </summary> /// <param name="url"></param> /// <param name="host"></param> /// <param name="code"></param> /// <param name="state"></param> /// <returns></returns> public ActionResult WechatOAuthCallBack(string url, string host, string code, string state) { var oauthService = new OAuthAPI(); if (string.IsNullOrEmpty(code)) { var callbackUrl = host + Url.Action("WechatOAuthCallback", "Wechat", new { url = url }); var wechatUrl = oauthService.GetAuthorizeUrl(WechatSetting.appId, callbackUrl, Guid.NewGuid().ToString(), OAuthScope.snsapi_base); return(Redirect(wechatUrl)); } var auth = oauthService.GetAccessToken(WechatSetting.appId, WechatSetting.appSecret, code); Session[WechatSetting.wechatOpenId] = auth.openid; url = HttpUtility.UrlDecode(url); return(Redirect(url)); }
private void m_oaApi_RequestTokenReceived(object sender, bool bSucceeded, string sErrorMessage, OAuthCredentials oaCredentials) { if (bSucceeded) { m_oaCredentials = oaCredentials; txtUrl.Text = OAuthAPI.GetRequestURL(m_oaCredentials); ToggleLoadingAnimation(false); ToggleButtons(true); m_aaStatus = (AddAccountStatus)((int)m_aaStatus + 1); UpdateFromStatus(); } else { MessageBox.Show(sErrorMessage, "OAuth Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); m_aaStatus = AddAccountStatus.Pin; UpdateFromStatus(); ToggleButtons(true); ToggleLoadingAnimation(false); } }
protected void btnGet_Click(object sender, EventArgs e) { if (Session["oauthAPI"] == null) { lblErrorMsg.Text = "请先提供授权"; return; } OAuthAPI oauthAPI = Session["oauthAPI"] as OAuthAPI; var methodVal = drpMethod.SelectedValue; MiniNet.OAuthAPI.HttpMethod method = MiniNet.OAuthAPI.HttpMethod.GET; if (methodVal.Equals("0")) { method = MiniNet.OAuthAPI.HttpMethod.GET; } else if (methodVal.Equals("1")) { method = MiniNet.OAuthAPI.HttpMethod.POST; } var content = ""; if (FileUpload1.HasFile) { var file = Request.Files[0]; var filename = file.FileName; byte[] bytes = new byte[file.ContentLength]; file.InputStream.Read(bytes, 0, file.ContentLength); content = oauthAPI.Call(txtApi.Text, txtApiParameter.Text, filename, bytes); } else { content = oauthAPI.Call(method, txtApi.Text, txtApiParameter.Text); } txtContent.Text = content; }
public void OAuthAPITestes_CreateCustomer() { OAuthAPI api = new OAuthAPI(BaseUrl, apiToken, apiKey); }
public Account(string sAccessKey, string sAccessSecret, string sUsername, string sPassword) { m_oaCredentials = OAuthAPI.GetCredentials(sAccessKey, sAccessSecret, sUsername, sPassword); Initialize(); }
public IActionResult LoginWithGoogle() { var page = OAuthAPI.GetGoogleLogin(_clientBaseAddress.BaseURLApi); return(Redirect(page)); }