当前位置: 首页>>代码示例>>C#>>正文


C# OpenIdRelyingParty.GetResponseAsync方法代码示例

本文整理汇总了C#中DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponseAsync方法的典型用法代码示例。如果您正苦于以下问题:C# OpenIdRelyingParty.GetResponseAsync方法的具体用法?C# OpenIdRelyingParty.GetResponseAsync怎么用?C# OpenIdRelyingParty.GetResponseAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty的用法示例。


在下文中一共展示了OpenIdRelyingParty.GetResponseAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnsolicitedAssertion

		public async Task UnsolicitedAssertion() {
			var opStore = new StandardProviderApplicationStore();
			Handle(RPUri).By(
				async req => {
					var rp = new OpenIdRelyingParty(new StandardRelyingPartyApplicationStore(), this.HostFactories);
					IAuthenticationResponse response = await rp.GetResponseAsync(req);
					Assert.That(response, Is.Not.Null);
					Assert.AreEqual(AuthenticationStatus.Authenticated, response.Status);
					return new HttpResponseMessage();
				});
			Handle(OPUri).By(
				async (req, ct) => {
					var op = new OpenIdProvider(opStore, this.HostFactories);
					return await this.AutoProviderActionAsync(op, req, ct);
				});
			this.RegisterMockRPDiscovery(ssl: false);

			{
				var op = new OpenIdProvider(opStore, this.HostFactories);
				Identifier id = GetMockIdentifier(ProtocolVersion.V20);
				var assertion = await op.PrepareUnsolicitedAssertionAsync(OPUri, RPRealmUri, id, OPLocalIdentifiers[0]);

				using (var httpClient = this.HostFactories.CreateHttpClient()) {
					using (var response = await httpClient.GetAsync(assertion.Headers.Location)) {
						response.EnsureSuccessStatusCode();
					}
				}
			}
		}
开发者ID:Adilson,项目名称:dotnetopenid,代码行数:29,代码来源:AuthenticationTests.cs

示例2: Authenticate

		public async Task<ActionResult> Authenticate(string returnUrl) {
			var rp = new OpenIdRelyingParty();
			var response = await rp.GetResponseAsync(Request);
			if (response != null) {
				switch (response.Status) {
					case AuthenticationStatus.Authenticated:
						// Make sure we have a user account for this guy.
						string identifier = response.ClaimedIdentifier; // convert to string so LinqToSQL expression parsing works.
						if (MvcApplication.DataContext.Users.FirstOrDefault(u => u.OpenIDClaimedIdentifier == identifier) == null) {
							MvcApplication.DataContext.Users.InsertOnSubmit(new User {
								OpenIDFriendlyIdentifier = response.FriendlyIdentifierForDisplay,
								OpenIDClaimedIdentifier = response.ClaimedIdentifier,
							});
						}

						FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
						return this.Redirect(returnUrl ?? Url.Action("Index", "Home"));
					default:
						ModelState.AddModelError(string.Empty, "An error occurred during login.");
						break;
				}
			}

			return this.View("LogOn");
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:25,代码来源:AccountController.cs

示例3: Authenticate

		public async Task<ActionResult> Authenticate() {
			var rp = new OpenIdRelyingParty(null);
			var response = await rp.GetResponseAsync(this.Request);
			if (response != null) {
				if (response.Status == AuthenticationStatus.Authenticated) {
					FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
					return this.Redirect(FormsAuthentication.GetRedirectUrl(response.ClaimedIdentifier, false));
				}
			}

			return this.RedirectToAction("Index", "Home");
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:12,代码来源:UserController.cs

示例4: Page_Load

		protected void Page_Load(object sender, EventArgs e) {
			this.RegisterAsyncTask(
				new PageAsyncTask(
					async ct => {
						using (var openid = new OpenIdRelyingParty()) {
							// In order to receive the UIRequest as a response, we must register a custom extension factory.
							openid.ExtensionFactories.Add(new UIRequestAtRelyingPartyFactory());

							var response = await openid.GetResponseAsync(new HttpRequestWrapper(Request), Response.ClientDisconnectedToken);
							if (response == null) {
								// Submit an OpenID request which Google must reply to immediately.
								// If the user hasn't established a trust relationship with this site yet,
								// Google will not give us the user identity, but they will tell us whether the user
								// at least has an active login session with them so we know whether to promote the
								// "Log in with Google" button.
								IAuthenticationRequest request =
									await
									openid.CreateRequestAsync(
										"https://www.google.com/accounts/o8/id", new HttpRequestWrapper(Request), Response.ClientDisconnectedToken);
								request.AddExtension(new UIRequest { Mode = UIModeDetectSession });
								request.Mode = AuthenticationRequestMode.Immediate;
								await request.RedirectToProviderAsync(new HttpContextWrapper(this.Context), Response.ClientDisconnectedToken);
							} else {
								if (response.Status == AuthenticationStatus.Authenticated) {
									this.YouTrustUsLabel.Visible = true;
								} else if (response.Status == AuthenticationStatus.SetupRequired) {
									// Google refused to authenticate the user without user interaction.
									// This is either because Google doesn't know who the user is yet,
									// or because the user hasn't indicated to Google to trust this site.
									// Google uniquely offers the RP a tip as to which of the above situations is true.
									// Figure out which it is.  In a real app, you might use this value to promote a 
									// Google login button on your site if you detect that a Google session exists.
									var ext = response.GetUntrustedExtension<UIRequest>();
									this.YouAreLoggedInLabel.Visible = ext != null && ext.Mode == UIModeDetectSession;
									this.YouAreNotLoggedInLabel.Visible = !this.YouAreLoggedInLabel.Visible;
								}
							}
						}
					}));
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:40,代码来源:DetectGoogleSession.aspx.cs

示例5: Page_Load

		protected async void Page_Load(object sender, EventArgs e) {
			this.openIdBox.Focus();
			using (OpenIdRelyingParty rp = new OpenIdRelyingParty()) {
				IAuthenticationResponse response = await rp.GetResponseAsync(new HttpRequestWrapper(this.Request), this.Response.ClientDisconnectedToken);
				if (response != null) {
					switch (response.Status) {
						case AuthenticationStatus.ExtensionsOnly:
							this.ExtensionResponsesPanel.Visible = true;

							// This is the "success" status we get when no authentication was requested.
							var sreg = response.GetExtension<ClaimsResponse>();
							if (sreg != null) {
								this.emailLabel.Text = sreg.Email;
								this.timeZoneLabel.Text = sreg.TimeZone;
								this.postalCodeLabel.Text = sreg.PostalCode;
								this.countryLabel.Text = sreg.Country;
								if (sreg.Gender.HasValue) {
									this.genderLabel.Text = sreg.Gender.Value.ToString();
								}
							}
							break;
						case AuthenticationStatus.Canceled:
							this.resultMessage.Text = "Canceled at OP.  This may be a sign that the OP doesn't support this message.";
							break;
						case AuthenticationStatus.Failed:
							this.resultMessage.Text = "OP returned a failure: " + response.Exception;
							break;
						case AuthenticationStatus.SetupRequired:
						case AuthenticationStatus.Authenticated:
						default:
							this.resultMessage.Text = "OP returned an unexpected response.";
							break;
					}
				}
			}
		}
开发者ID:Balamir,项目名称:DotNetOpenAuth,代码行数:36,代码来源:NoIdentityOpenId.aspx.cs

示例6: OpenIdCallback

        public async Task<ActionResult> OpenIdCallback(string returnUrl)
        {
            var model = new LoginModel { ReturnUrl = returnUrl };
            var openId = new OpenIdRelyingParty();
            var openIdResponseTask = openId.GetResponseAsync();

            await openIdResponseTask;

            var openIdResponse = openIdResponseTask.Result;
            if (openIdResponse.Status == AuthenticationStatus.Authenticated)
            {
                var friendlyName = GetFriendlyName(openIdResponse);

                var isPersistentCookie = true;
                SetAuthCookie(openIdResponse.ClaimedIdentifier, isPersistentCookie, friendlyName);

                return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
            }

            model.Message = "Sorry, login failed.";
            return View("Login", model);
        }
开发者ID:4Rebin,项目名称:NBlog,代码行数:22,代码来源:AuthenticationController.cs

示例7: AssertionWithEndpointFilter

		public async Task AssertionWithEndpointFilter() {
			var opStore = new StandardProviderApplicationStore();
			Handle(RPUri).By(
				async req => {
					var rp = new OpenIdRelyingParty(new StandardRelyingPartyApplicationStore(), this.HostFactories);

					// Rig it to always deny the incoming OP
					rp.EndpointFilter = op => false;

					// Receive the unsolicited assertion
					var response = await rp.GetResponseAsync(req);
					Assert.That(response, Is.Not.Null);
					Assert.AreEqual(AuthenticationStatus.Failed, response.Status);
					return new HttpResponseMessage();
				});
			this.RegisterAutoProvider();
			{
				var op = new OpenIdProvider(opStore, this.HostFactories);
				Identifier id = GetMockIdentifier(ProtocolVersion.V20);
				var assertion = await op.PrepareUnsolicitedAssertionAsync(OPUri, GetMockRealm(false), id, id);
				using (var httpClient = this.HostFactories.CreateHttpClient()) {
					using (var response = await httpClient.GetAsync(assertion.Headers.Location)) {
						response.EnsureSuccessStatusCode();
					}
				}
			}
		}
开发者ID:Adilson,项目名称:dotnetopenid,代码行数:27,代码来源:OpenIdRelyingPartyTests.cs


注:本文中的DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.GetResponseAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。