本文整理汇总了C#中DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty类的典型用法代码示例。如果您正苦于以下问题:C# OpenIdRelyingParty类的具体用法?C# OpenIdRelyingParty怎么用?C# OpenIdRelyingParty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenIdRelyingParty类属于DotNetOpenAuth.OpenId.RelyingParty命名空间,在下文中一共展示了OpenIdRelyingParty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: Authenticate
/// <summary>
/// Authenicates a user based on the information in the HTTP request.
/// </summary>
/// <returns></returns>
public override void Authenticate(AuthenticationRequest request, AuthenticationResponse response)
{
// Only execute the authentication if the user is not known yet
if (response.Principal == null)
{
// Get OpenID provider's response from the http context
using (var openid = new OpenIdRelyingParty())
{
var openIDResponse = openid.GetResponse();
// TODO: figure out which OpenID provider sent the response
// and associate with the right authenticator
if (response != null)
{
switch (openIDResponse.Status)
{
case AuthenticationStatus.Authenticated:
response.SetPrincipal(CreatePrincipal(openIDResponse));
break;
case AuthenticationStatus.Canceled:
case AuthenticationStatus.Failed:
throw new System.Security.Authentication.AuthenticationException("OpenID authentication failed.", openIDResponse.Exception); // TODO
case AuthenticationStatus.ExtensionsOnly:
case AuthenticationStatus.SetupRequired:
throw new InvalidOperationException();
default:
throw new NotImplementedException();
}
}
}
}
}
示例3: Index
//
// GET: /Home/
//STEAM_0:0:68926576
//SteamWebAPI.SetGlobalKey("CFDCF16D4EC9D68762FBE9C61B43892D");
//vmykel
//wheniwasyourman
public ActionResult Index()
{
OpenIdRelyingParty openid = new OpenIdRelyingParty();
OpenIdLogin openlog = new OpenIdLogin();
openid.SecuritySettings.AllowDualPurposeIdentifiers = true;
IAuthenticationResponse response = openid.GetResponse();
if (response != null)
{
string regex = Request.QueryString["openid.identity"];
//string youareel= "http://steamcommunity.com/openid/id/76561198131281243";
string[] str = regex.Split('/');
string id = str[5];
Session["user"] = id;
FormsAuthentication.SetAuthCookie(id, false);
if(!User.Identity.IsAuthenticated)
{
return RedirectToAction("Index");
}
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index","Account");
}
}
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Account");
}
return View();
}
示例4: Register
public static void Register(OpenIdRelyingParty relyingParty) {
if (relyingParty == null) {
throw new ArgumentNullException("relyingParty");
}
relyingParty.ExtensionFactories.Add(new Acme());
}
示例5: 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;
}
}
示例6: SignIn
public ActionResult SignIn()
{
var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var claimsResponse = response.GetExtension<ClaimsResponse>();
FormsAuthentication.SetAuthCookie(claimsResponse.Email, true);
return RedirectToAction("Index", "Member");
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier",
"Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier",
"Login failed using the provided OpenID identifier");
break;
}
}
return View();
}
示例7: ExtensionFactories
public void ExtensionFactories() {
var rp = new OpenIdRelyingParty(null);
var factories = rp.ExtensionFactories;
Assert.IsNotNull(factories);
Assert.AreEqual(1, factories.Count);
Assert.IsInstanceOf<StandardOpenIdExtensionFactory>(factories[0]);
}
示例8: LogOn
public ActionResult LogOn(string from)
{
var openid = new OpenIdRelyingParty();
IAuthenticationResponse response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var sreg = response.GetExtension<ClaimsResponse>();
if (sreg != null)
{
Session.Add("Email", sreg.Email);
Session.Add("FullName", sreg.FullName);
}
FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
break;
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier", "Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier", "Login failed using the provided OpenID identifier");
break;
}
}
return View();
}
示例9: 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;
}
示例10: Login
public ActionResult Login()
{
var openid = new OpenIdRelyingParty();
IAuthenticationResponse response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var user = EnsureUserExists(response);
FormsAuthentication.RedirectFromLoginPage(
user.email, false);
break;
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier",
"Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier",
"Login failed using the provided OpenID identifier");
break;
}
}
return View();
}
示例11: 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();
}
}
示例12: 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();
}
示例13: OpenIdRelyingParty
private static OpenIdRelyingParty openid; // = new OpenIdRelyingParty();
#endregion Fields
#region Constructors
static GoogleOAuth()
{
if (System.Web.HttpContext.Current != null)
{
openid = new OpenIdRelyingParty();
}
}
示例14: LogOn
//
// GET: /Account/LogOn
public ActionResult LogOn()
{
var openid = new OpenIdRelyingParty();
IAuthenticationResponse response = openid.GetResponse();
if (response != null)
{
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
RedirectFromLoginPage(
response.ClaimedIdentifier, "LogOn");
break;
case AuthenticationStatus.Canceled:
ModelState.AddModelError("loginIdentifier",
"Login was cancelled at the provider");
break;
case AuthenticationStatus.Failed:
ModelState.AddModelError("loginIdentifier",
"Login failed using the provided OpenID identifier");
break;
}
}
return View();
}
示例15: 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;
}
}
}