本文整理汇总了C#中DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest方法的典型用法代码示例。如果您正苦于以下问题:C# OpenIdRelyingParty.CreateRequest方法的具体用法?C# OpenIdRelyingParty.CreateRequest怎么用?C# OpenIdRelyingParty.CreateRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty
的用法示例。
在下文中一共展示了OpenIdRelyingParty.CreateRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
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 = openid.GetResponse();
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 = openid.CreateRequest("https://www.google.com/accounts/o8/id");
request.AddExtension(new UIRequest { Mode = UIModeDetectSession });
request.Mode = AuthenticationRequestMode.Immediate;
request.RedirectToProvider();
} 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;
}
}
}
}
示例2: CreateRequest
public IAuthenticationRequest CreateRequest(string realmUrl, string returnUrl)
{
if (!Uri.IsWellFormedUriString(realmUrl, UriKind.Relative))
{
throw new ArgumentException("Value is not a well formed relative uri string", "realmUrl");
}
if (!Uri.IsWellFormedUriString(returnUrl, UriKind.Relative))
{
throw new ArgumentException("Value is not a well formed relative uri string", "returnUrl");
}
IAuthenticationRequest request;
var baseUri = new Uri(_request.Url, "/");
var realmUri = new Uri(baseUri, realmUrl);
var returnToUri = new Uri(baseUri, returnUrl);
using (var openIdRelyingParty = new OpenIdRelyingParty())
{
request = openIdRelyingParty.CreateRequest(Identifier.Parse("https://www.google.com/accounts/o8/id"), new Realm(realmUri), returnToUri);
}
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Require
});
return request;
}
示例3: IsValidLogin
public void IsValidLogin(Uri serviceUri)
{
var result = false;
var openid = new OpenIdRelyingParty();
if (openid.GetResponse() == null) {
// Stage 2: user submitting Identifier
openid.CreateRequest(HttpRequest.Request.Form["openid_identifier"]).RedirectToProvider();
}
else {
// Stage 3: OpenID Provider sending assertion response
switch (openid.Response.Status) {
case AuthenticationStatus.Authenticated:
FormsAuthenticationProvider.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
break;
case AuthenticationStatus.Canceled:
ViewData["Message"] = "Canceled at provider";
RenderView("Login");
break;
case AuthenticationStatus.Failed:
ViewData["Message"] = openid.Response.Exception.Message;
RenderView("Login");
break;
}
}
}
示例4: BeginAuth
public ActionResult BeginAuth()
{
var provider = "http://steamcommunity.com/openid";
var realm = new DotNetOpenAuth.OpenId.Realm(string.Format("{0}{1}{2}", this.Request.Url.Scheme, Uri.SchemeDelimiter, this.Request.Url.Authority));
var returnTo = new Uri(this.Request.Url, this.Url.Action("EndAuth"));
using (var rp = new OpenIdRelyingParty())
{
var request = rp.CreateRequest(provider, realm, returnTo);
var claimsRequest = new ClaimsRequest
{
Email = DemandLevel.Require,
BirthDate = DemandLevel.Request,
Country = DemandLevel.Request,
FullName = DemandLevel.Request,
Gender = DemandLevel.Request,
Language = DemandLevel.Request,
Nickname = DemandLevel.Request,
PostalCode = DemandLevel.Request,
TimeZone = DemandLevel.Request,
};
request.AddExtension(claimsRequest);
return request.RedirectingResponse.AsActionResult();
}
}
示例5: Login
public ActionResult Login(LoginViewModel model)
{
if (!Identifier.IsValid(model.IdentityProviderUri))
{
throw new Exception("The specified login identifier is invalid");
}
var openId = new OpenIdRelyingParty();
var request = openId.CreateRequest(Identifier.Parse(model.IdentityProviderUri));
request.AddExtension(new ClaimsRequest
{
BirthDate = DemandLevel.NoRequest,
Email = DemandLevel.Request,
FullName = DemandLevel.NoRequest,
TimeZone = DemandLevel.Request,
Nickname = DemandLevel.Request,
Country = DemandLevel.NoRequest,
Gender = DemandLevel.NoRequest,
Language = DemandLevel.NoRequest,
PostalCode = DemandLevel.NoRequest
});
return request.RedirectingResponse.AsActionResult();
}
示例6: LoginToGoogle
void LoginToGoogle()
{
try
{
using (OpenIdRelyingParty party = new OpenIdRelyingParty())
{
IAuthenticationRequest request = party.CreateRequest(ConfigurationManager.AppSettings["google-auth-path"]);
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
request.AddExtension(fetch);
//request.AddExtension(new ClaimsRequest
//{
// Country = DemandLevel.Request,
// Email = DemandLevel.Request,
// Gender = DemandLevel.Require,
// PostalCode = DemandLevel.Require,
// TimeZone = DemandLevel.Require,
//});
request.RedirectToProvider();
}
}
catch (ProtocolException ex)
{
LabelStatus.Text = ex.Message;
}
}
示例7: beginButton_Click
protected void beginButton_Click(object sender, EventArgs e)
{
if (!this.Page.IsValid) {
return; // don't login if custom validation failed.
}
try {
using (OpenIdRelyingParty rp = new OpenIdRelyingParty()) {
var request = rp.CreateRequest(this.openIdBox.Text);
request.IsExtensionOnly = true;
// This is where you would add any OpenID extensions you wanted
// to include in the request.
request.AddExtension(new ClaimsRequest {
Country = DemandLevel.Request,
Gender = DemandLevel.Require,
PostalCode = DemandLevel.Require,
TimeZone = DemandLevel.Require,
});
request.RedirectToProvider();
}
} catch (ProtocolException ex) {
// The user probably entered an Identifier that
// was not a valid OpenID endpoint.
this.openidValidator.Text = ex.Message;
this.openidValidator.IsValid = false;
}
}
示例8: OpenIdLogin
public ActionResult OpenIdLogin(string openidIdentifier)
{
if (!Identifier.IsValid(openidIdentifier))
{
ModelState.AddModelError("loginIdentifier",
"The specified login identifier is invalid");
return View("LogOn");
}
else
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(
Identifier.Parse(openidIdentifier));
// Require some additional data
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Require,
FullName = DemandLevel.Request
});
return request.RedirectingResponse.AsActionResult();
}
}
示例9: LogOn
public ActionResult LogOn(string loginIdentifier)
{
if (!Identifier.IsValid(loginIdentifier))
{
ModelState.AddModelError("loginIdentifier",
"The specified login identifier is invalid");
return View();
}
else
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(Identifier.Parse(loginIdentifier));
/*
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Require,
FullName = DemandLevel.Require§
});
*/
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
request.AddExtension(fetch);
return request.RedirectingResponse.AsActionResult();
}
}
示例10: OpenID
public ActionResult OpenID(string openid_identifier)
{
var openid = new OpenIdRelyingParty();
IAuthenticationRequest request = openid.CreateRequest(Identifier.Parse(openid_identifier));
return request.RedirectingResponse.AsActionResult();
}
示例11: MakeRequest
private ActionResult MakeRequest(string loginIdentifier)
{
if (!Identifier.IsValid(loginIdentifier))
{
TempData.FlashError("The loginIdentifier is not valid.");
return RedirectToAction("SignIn", "Authentication");
}
else
{
var openid = new OpenIdRelyingParty();
var replyTo = Url.Action("CompleteRequest", "OpenId", null, Request.Url.Scheme);
var replyToUri = new Uri(replyTo, UriKind.Absolute);
var request = openid.CreateRequest(
Identifier.Parse(loginIdentifier), Realm.AutoDetect,
replyToUri);
// Require some additional data
request.AddExtension(new ClaimsRequest
{
BirthDate = DemandLevel.NoRequest,
Email = DemandLevel.Require,
FullName = DemandLevel.Require
});
return request.RedirectingResponse.AsActionResult();
}
}
示例12: CreateRequestDumbMode
public void CreateRequestDumbMode()
{
var rp = new OpenIdRelyingParty(null);
Identifier id = this.GetMockIdentifier(ProtocolVersion.V20);
var authReq = rp.CreateRequest(id, RPRealmUri, RPUri);
CheckIdRequest requestMessage = (CheckIdRequest)authReq.RedirectingResponse.OriginalMessage;
Assert.IsNull(requestMessage.AssociationHandle);
}
示例13: Execute
public void Execute(AuthenticateInputModel inputModel)
{
var party = new OpenIdRelyingParty();
var request = party.CreateRequest(inputModel.GetIdentifier());
request.RedirectToProvider();
}
示例14: Page_Load
/// <summary>
/// Action Results for Index, uses DotNetOpenAuth for creating OpenId Request with Intuit
/// and handling response recieved.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">Event Args.</param>
protected void Page_Load(object sender, EventArgs e)
{
//OpenId Relying Party
OpenIdRelyingParty openid = new OpenIdRelyingParty();
var openIdIdentifier = ConfigurationManager.AppSettings["openid_identifier"];
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(openIdIdentifier, out id))
{
try
{
IAuthenticationRequest request = openid.CreateRequest(openIdIdentifier);
FetchRequest fetch = new FetchRequest();
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email));
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName));
request.AddExtension(fetch);
request.RedirectToProvider();
}
catch (ProtocolException ex)
{
throw ex;
}
}
}
else
{
if (response.FriendlyIdentifierForDisplay == null)
{
Response.Redirect("/OpenIdHandler.aspx");
}
// Stage 3: OpenID Provider sending assertion response
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FetchResponse fetch = response.GetExtension<FetchResponse>();
if (fetch != null)
{
Session["OpenIdResponse"] = "True";
Session["FriendlyEmail"] = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
Session["FriendlyName"] = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);
}
//Check if user disconnected from the App Center
if (Request.QueryString["disconnect"] != null && Request.QueryString["disconnect"].ToString(CultureInfo.InvariantCulture) == "true")
{
Session["Flag"] = true;
Response.Redirect("CleanupOnDisconnect.aspx");
}
else
{
Response.Redirect("Default.aspx");
}
}
}
示例15: OpenId
public ActionResult OpenId(LoginModel model)
{
Identifier id;
if (Identifier.TryParse(model.OpenID_Identifier, out id))
{
try
{
model.Config = _services.Config.Current;
var openId = new OpenIdRelyingParty();
returnToUrl = new Uri(Url.Action("OpenIdCallback", "Authentication", new { ReturnUrl = model.ReturnUrl }, Request.Url.Scheme), UriKind.Absolute);
// hack for google oauth2
if (model.OpenID_Identifier.Contains("google"))
{
client = new GoogleOAuth2Client(model.Config.ClientId, model.Config.ClientSecret);
client.RequestAuthentication(this.HttpContext, returnToUrl);
GoogleOAuth2Client.RewriteRequest();
return Redirect(returnToUrl.ToString());
}
else
{
var request = openId.CreateRequest(id, Realm.AutoDetect, returnToUrl);
// add request for name and email using sreg (OpenID Simple Registration
// Extension)
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Require,
FullName = DemandLevel.Require,
Nickname = DemandLevel.Require
});
// also add AX request
var axRequest = new FetchRequest();
axRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
axRequest.Attributes.AddRequired(WellKnownAttributes.Name.First);
axRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);
axRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(axRequest);
var redirectingResponse = request.RedirectingResponse;
return redirectingResponse.AsActionResult();
}
}
catch (ProtocolException ex)
{
model.Message = ex.Message;
return View("Login", model);
}
}
else
{
model.Message = "Invalid identifier";
return View("Login", model);
}
}