本文整理汇总了C#中DotNetOpenAuth.OpenId.Extensions.AttributeExchange.FetchRequest类的典型用法代码示例。如果您正苦于以下问题:C# FetchRequest类的具体用法?C# FetchRequest怎么用?C# FetchRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FetchRequest类属于DotNetOpenAuth.OpenId.Extensions.AttributeExchange命名空间,在下文中一共展示了FetchRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBeforeSendingAuthenticationRequest
protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request)
{
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
request.AddExtension(fetchRequest);
}
示例2: PrepareOpenIdRequest
internal AuthenticationResult PrepareOpenIdRequest(string providerUrl, Uri returnUrl)
{
Identifier identifier;
if (Identifier.TryParse(providerUrl, out identifier))
{
try
{
IAuthenticationRequest request = relyingParty.CreateRequest(identifier, Realm.AutoDetect, returnUrl);
FetchRequest fetch = new FetchRequest(); // request the authentication provider for some additional information.
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
request.AddExtension(fetch);
return new AuthenticationResult
{
Status = ConnectionStatus.RedirectToProvider,
Action = request.RedirectingResponse.AsActionResult()
};
}
catch (ProtocolException exception)
{
return AuthenticationException(exception);
}
}
return AbortedAuthentication(Common.Resources.Authentication.InvalidOpenIdIdentifier);
}
示例3: RequestAuthentication
private Interfaces.IAuthenticationResponse RequestAuthentication(Interfaces.IAuthenticationRequest request)
{
Identifier id;
if (!Identifier.TryParse(request.Url, out id))
{
_logger.Info(string.Format("OpenID Error...invalid url. url='{0}'", request.Url));
return Factory.AuthenticationResponse(Interfaces.AuthenticationState.Errored);
}
try
{
var authenticationRequest = _openIdRelyingParty.CreateRequest(request.Url);
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
authenticationRequest.AddExtension(fetch);
var actionResult = authenticationRequest.RedirectingResponse.AsActionResult();
return Factory.AuthenticationResponse(actionResult);
}
catch (ProtocolException ex)
{
_logger.Error("OpenID Exception...", ex);
return Factory.AuthenticationResponse(Interfaces.AuthenticationState.Errored);
}
}
示例4: Login
public string Login(string callBackUrl)
{
var response = _openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(OpenIdUrl, out id))
{
try
{
var callBackUri = new Uri(callBackUrl);
var request = _openid.CreateRequest(OpenIdUrl, new Realm(callBackUri), callBackUri);
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Middle);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Alias);
request.AddExtension(fetch);
request.RedirectToProvider();
return null;
}
catch (ProtocolException ex)
{
return null;
}
}
}
return null;
}
示例5: 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;
}
}
示例6: CreateFetchRequest
/// <summary>
/// Creates the fetch request.
/// </summary>
/// <returns></returns>
private static FetchRequest CreateFetchRequest()
{
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
return fetchRequest;
}
示例7: OnBeforeSendingAuthenticationRequest
protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request)
{
FetchRequest extension = new FetchRequest();
extension.Attributes.AddRequired("http://axschema.org/contact/email");
extension.Attributes.AddRequired("http://axschema.org/namePerson");
request.AddExtension(extension);
}
示例8: OpenId
public ActionResult OpenId(string openIdUrl)
{
var response = _openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(openIdUrl, out id))
{
try
{
var request = _openid.CreateRequest(openIdUrl);
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);
return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException)
{
//_logger.Error("OpenID Exception...", ex);
return this.RedirectToAction(x => x.SignIn());
}
}
//_logger.Info("OpenID Error...invalid url. url='" + openIdUrl + "'");
return this.RedirectToAction(x => x.SignIn());
}
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var fetch = response.GetExtension<FetchResponse>();
var firstName = "";
var lastName = "";
var email = "";
if (fetch != null)
{
firstName = fetch.GetAttributeValue(WellKnownAttributes.Name.First);
lastName = fetch.GetAttributeValue(WellKnownAttributes.Name.Last);
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
return CreateUser(new CreateUser
{
UserName = response.ClaimedIdentifier,
FirstName = firstName,
LastName = lastName,
Email = email
});
case AuthenticationStatus.Canceled:
//_logger.Info("OpenID: Cancelled at provider.");
return this.RedirectToAction(x => x.SignIn());
case AuthenticationStatus.Failed:
//_logger.Error("OpenID Exception...", response.Exception);
return this.RedirectToAction(x => x.SignIn());
}
return this.RedirectToAction(x => x.SignIn());
}
示例9: OnBeforeSendingAuthenticationRequest
/// <summary>
/// Called just before the authentication request is sent to service provider.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request) {
// Attribute Exchange extensions
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, isRequired: true));
fetchRequest.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName, isRequired: false));
request.AddExtension(fetchRequest);
}
示例10: 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");
}
}
}
示例11: Index
/// <summary>
/// Action Results for Index, uses DotNetOpenAuth for creating OpenId Request with Intuit
/// and handling response recieved.
/// </summary>
/// <returns></returns>
public RedirectResult Index()
{
var openid_identifier = ConfigurationManager.AppSettings["openid_identifier"].ToString(); ;
var response = openid.GetResponse();
if (response == null)
{
// Stage 2: user submitting Identifier
Identifier id;
if (Identifier.TryParse(openid_identifier, out id))
{
try
{
IAuthenticationRequest request = openid.CreateRequest(openid_identifier);
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("/OpenId");
}
// Stage 3: OpenID Provider sending assertion response, storing the response in Session object is only for demonstration purpose
Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
FetchResponse fetch = response.GetExtension<FetchResponse>();
if (fetch != null)
{
Session["OpenIdResponse"] = "True";
Session["FriendlyEmail"] = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);// emailAddresses.Count > 0 ? emailAddresses[0] : null;
Session["FriendlyName"] = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);//fullNames.Count > 0 ? fullNames[0] : null;
//get the Oauth Access token for the user from OauthAccessTokenStorage.xml
OauthAccessTokenStorageHelper.GetOauthAccessTokenForUser(Session["FriendlyEmail"].ToString(), this);
}
}
string query = Request.Url.Query;
if (!string.IsNullOrWhiteSpace(query) && query.ToLower().Contains("disconnect=true"))
{
Session["accessToken"] = "dummyAccessToken";
Session["accessTokenSecret"] = "dummyAccessTokenSecret";
Session["Flag"] = true;
return Redirect("/CleanupOnDisconnect/Index");
}
return Redirect("/Home/index");
}
示例12: RedirectToProvider
public ActionResult RedirectToProvider(string providerUrl, string returnUrl, FetchRequest fetch)
{
var baseUrl = HttpContext.Current.Request.ToPublicUrl(new Uri("/", UriKind.Relative));
var realm = new Realm(baseUrl);
var authenticationRequest = _relyingParty.CreateRequest(providerUrl, realm, new Uri(returnUrl,UriKind.Absolute));
authenticationRequest.AddExtension(fetch);
return new OutgoingRequestActionResult(authenticationRequest.RedirectingResponse);
}
示例13: RedirectToProvider
public ActionResult RedirectToProvider(string providerUrl, string returnUrl, FetchRequest fetch)
{
IAuthenticationRequest authenticationRequest = this.relyingParty.CreateRequest(providerUrl,
Realm.AutoDetect,
new Uri(returnUrl));
authenticationRequest.AddExtension(fetch);
return new OutgoingRequestActionResult(authenticationRequest.RedirectingResponse);
}
示例14: 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);
}
}
示例15: OnBeforeSendingAuthenticationRequest
/// <summary>
/// Called just before the authentication request is sent to service provider.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
protected override void OnBeforeSendingAuthenticationRequest(IAuthenticationRequest request) {
// Attribute Exchange extensions
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetchRequest.Attributes.AddOptional(WellKnownAttributes.Contact.HomeAddress.Country);
fetchRequest.Attributes.AddOptional(WellKnownAttributes.Name.First);
fetchRequest.Attributes.AddOptional(WellKnownAttributes.Name.Last);
request.AddExtension(fetchRequest);
}