本文整理汇总了C#中IAuthenticationResponse类的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticationResponse类的具体用法?C# IAuthenticationResponse怎么用?C# IAuthenticationResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAuthenticationResponse类属于命名空间,在下文中一共展示了IAuthenticationResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessUserAuthorizationAsync
/// <summary>
/// Processes an incoming authorization-granted message from an SP and obtains an access token.
/// </summary>
/// <param name="openIdAuthenticationResponse">The OpenID authentication response that may be carrying an authorized request token.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The access token, or null if OAuth authorization was denied by the user or service provider.
/// </returns>
/// <remarks>
/// The access token, if granted, is automatically stored in the <see cref="ConsumerBase.TokenManager" />.
/// The token manager instance must implement <see cref="IOpenIdOAuthTokenManager" />.
/// </remarks>
public async Task<AccessTokenResponse> ProcessUserAuthorizationAsync(IAuthenticationResponse openIdAuthenticationResponse, CancellationToken cancellationToken = default(CancellationToken)) {
Requires.NotNull(openIdAuthenticationResponse, "openIdAuthenticationResponse");
// The OAuth extension is only expected in positive assertion responses.
if (openIdAuthenticationResponse.Status != AuthenticationStatus.Authenticated) {
return null;
}
// Retrieve the OAuth extension
var positiveAuthorization = openIdAuthenticationResponse.GetExtension<AuthorizationApprovedResponse>();
if (positiveAuthorization == null) {
return null;
}
using (var client = this.CreateHttpClient(new AccessToken(positiveAuthorization.RequestToken, string.Empty))) {
var request = new HttpRequestMessage(this.ServiceProvider.TokenRequestEndpointMethod, this.ServiceProvider.TokenRequestEndpoint);
using (var response = await client.SendAsync(request, cancellationToken)) {
response.EnsureSuccessStatusCode();
// Parse the response and ensure that it meets the requirements of the OAuth 1.0 spec.
string content = await response.Content.ReadAsStringAsync();
var responseData = HttpUtility.ParseQueryString(content);
string accessToken = responseData[Protocol.TokenParameter];
string tokenSecret = responseData[Protocol.TokenSecretParameter];
ErrorUtilities.VerifyProtocol(!string.IsNullOrEmpty(accessToken), MessagingStrings.RequiredParametersMissing, typeof(AuthorizedTokenResponse).Name, Protocol.TokenParameter);
ErrorUtilities.VerifyProtocol(tokenSecret != null, MessagingStrings.RequiredParametersMissing, typeof(AuthorizedTokenResponse).Name, Protocol.TokenSecretParameter);
responseData.Remove(Protocol.TokenParameter);
responseData.Remove(Protocol.TokenSecretParameter);
return new AccessTokenResponse(accessToken, tokenSecret, responseData);
}
}
}
示例2: SetUserInformationGeneric
private void SetUserInformationGeneric(IAuthenticationResponse response)
{
var userdata = response.GetExtension<ClaimsResponse>();
var email = userdata.Email;
FullName = userdata.FullName;
Email = email;
}
示例3: ProcessUserAuthorization
/// <summary>
/// Processes an incoming authorization-granted message from an SP and obtains an access token.
/// </summary>
/// <param name="openIdAuthenticationResponse">The OpenID authentication response that may be carrying an authorized request token.</param>
/// <returns>
/// The access token, or null if OAuth authorization was denied by the user or service provider.
/// </returns>
/// <remarks>
/// The access token, if granted, is automatically stored in the <see cref="ConsumerBase.TokenManager"/>.
/// The token manager instance must implement <see cref="IOpenIdOAuthTokenManager"/>.
/// </remarks>
public AuthorizedTokenResponse ProcessUserAuthorization(IAuthenticationResponse openIdAuthenticationResponse) {
Requires.NotNull(openIdAuthenticationResponse, "openIdAuthenticationResponse");
Requires.ValidState(this.TokenManager is IOpenIdOAuthTokenManager);
var openidTokenManager = this.TokenManager as IOpenIdOAuthTokenManager;
ErrorUtilities.VerifyOperation(openidTokenManager != null, OAuthStrings.OpenIdOAuthExtensionRequiresSpecialTokenManagerInterface, typeof(IOpenIdOAuthTokenManager).FullName);
// The OAuth extension is only expected in positive assertion responses.
if (openIdAuthenticationResponse.Status != AuthenticationStatus.Authenticated) {
return null;
}
// Retrieve the OAuth extension
var positiveAuthorization = openIdAuthenticationResponse.GetExtension<AuthorizationApprovedResponse>();
if (positiveAuthorization == null) {
return null;
}
// Prepare a message to exchange the request token for an access token.
// We are careful to use a v1.0 message version so that the oauth_verifier is not required.
var requestAccess = new AuthorizedTokenRequest(this.ServiceProvider.AccessTokenEndpoint, Protocol.V10.Version) {
RequestToken = positiveAuthorization.RequestToken,
ConsumerKey = this.ConsumerKey,
};
// Retrieve the access token and store it in the token manager.
openidTokenManager.StoreOpenIdAuthorizedRequestToken(this.ConsumerKey, positiveAuthorization);
var grantAccess = this.Channel.Request<AuthorizedTokenResponse>(requestAccess);
this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, positiveAuthorization.RequestToken, grantAccess.AccessToken, grantAccess.TokenSecret);
// Provide the caller with the access token so it may be associated with the user
// that is logging in.
return grantAccess;
}
示例4: SetCommenterValuesFromOpenIdResponse
private static void SetCommenterValuesFromOpenIdResponse(IAuthenticationResponse response, Commenter commenter)
{
var claimsResponse = response.GetExtension<ClaimsResponse>();
if (claimsResponse != null)
{
if (string.IsNullOrWhiteSpace(commenter.Name) && string.IsNullOrWhiteSpace(claimsResponse.Nickname) == false)
commenter.Name = claimsResponse.Nickname;
else if (string.IsNullOrWhiteSpace(commenter.Name) && string.IsNullOrWhiteSpace(claimsResponse.FullName) == false)
commenter.Name = claimsResponse.FullName;
if (string.IsNullOrWhiteSpace(commenter.Email) && string.IsNullOrWhiteSpace(claimsResponse.Email) == false)
commenter.Email = claimsResponse.Email;
}
var fetchResponse = response.GetExtension<FetchResponse>();
if (fetchResponse != null) // let us try from the attributes
{
if (string.IsNullOrWhiteSpace(commenter.Email))
commenter.Email = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email);
if (string.IsNullOrWhiteSpace(commenter.Name))
{
commenter.Name = fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName) ??
fetchResponse.GetAttributeValue(WellKnownAttributes.Name.First) + " " +
fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Last);
}
if (string.IsNullOrWhiteSpace(commenter.Url))
{
commenter.Url = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Web.Blog) ??
fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Web.Homepage);
}
}
}
示例5: GetUserClaim
public virtual UserClaim GetUserClaim(IAuthenticationResponse response)
{
if (response == null) return null;
switch (response.Status) {
case AuthenticationStatus.Authenticated:
var claimsResponse = response.GetExtension<ClaimsResponse>();
if (claimsResponse != null) {
return new UserClaim {
Username = claimsResponse.Nickname,
Email = claimsResponse.Email,
Name = claimsResponse.FullName,
Identifier = response.FriendlyIdentifierForDisplay
};
}
return null;
case AuthenticationStatus.Canceled:
case AuthenticationStatus.Failed:
return null;
}
return null;
}
示例6: SetUserInformationFromGoogle
private void SetUserInformationFromGoogle(IAuthenticationResponse response)
{
var userdata = response.GetExtension<FetchResponse>();
var firstname = userdata.GetAttributeValue(WellKnownAttributes.Name.First);
var lastname = userdata.GetAttributeValue(WellKnownAttributes.Name.Last);
FullName = firstname + " " + lastname;
Email = userdata.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
示例7: HandleUnknownUser
protected override string HandleUnknownUser(IAuthenticationResponse response)
{
string username = response.ClaimedIdentifier.ToString();
string email = response.ClaimedIdentifier.ToString();
string comment = null;
var sreg = response.GetExtension<DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.ClaimsResponse>();
if (sreg != null)
{
if (sreg.Nickname != null)
{
comment = sreg.Nickname;
}
if (sreg.Email != null)
{
email = sreg.Email;
}
}
var ax = response.GetExtension<DotNetOpenAuth.OpenId.Extensions.AttributeExchange.FetchResponse>();
if (ax != null)
{
if (ax.Attributes.Contains(WellKnownAttributes.Contact.Email))
{
IList<string> emailAddresses = ax.Attributes[WellKnownAttributes.Contact.Email].Values;
email = emailAddresses.Count > 0 ? emailAddresses[0] : email;
}
if (ax.Attributes.Contains(WellKnownAttributes.Name.Alias))
{
IList<string> aliasNames = ax.Attributes[WellKnownAttributes.Name.Alias].Values;
comment = aliasNames.Count > 0 ? aliasNames[0] : comment;
}
}
try
{
var user = Membership.CreateUser(username, Guid.NewGuid().ToString(), email);
NHOpenIDMembershipProvider idprov = Provider as NHOpenIDMembershipProvider;
MembershipCreateStatus status;
idprov.AddIdToUser(user, response.ClaimedIdentifier, out status);
if (status == MembershipCreateStatus.Success)
{
if (String.IsNullOrEmpty(comment)) {
user.Comment = email;
} else {
user.Comment = comment;
}
Provider.UpdateUser(user);
return user.UserName;
}
else
{
Provider.DeleteUser(user.UserName, true);
}
}
catch (MembershipCreateUserException)
{
return null;
}
return null;
}
示例8: TryGetOpenIdResponse
public override bool TryGetOpenIdResponse(out IAuthenticationResponse openIdResponse)
{
openIdResponse = openIdRelyingParty.GetResponse();
if (openIdResponse.IsNull())
{
return false;
}
return true;
}
示例9: AuthenticationResponseShim
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
/// </summary>
/// <param name="response">The response.</param>
internal AuthenticationResponseShim(IAuthenticationResponse response) {
Contract.Requires<ArgumentNullException>(response != null);
this.response = response;
var claimsResponse = this.response.GetExtension<ClaimsResponse>();
if (claimsResponse != null) {
this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
}
}
示例10: AuthenticationResponseShim
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
/// </summary>
/// <param name="response">The response.</param>
internal AuthenticationResponseShim(IAuthenticationResponse response) {
Requires.NotNull(response, "response");
this.response = response;
var claimsResponse = this.response.GetExtension<ClaimsResponse>();
if (claimsResponse != null) {
this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
}
}
示例11: AuthenticationResponseShim
/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
/// </summary>
/// <param name="response">The response.</param>
internal AuthenticationResponseShim(IAuthenticationResponse response)
{
Contract.Requires(response != null);
ErrorUtilities.VerifyArgumentNotNull(response, "response");
this.response = response;
var claimsResponse = this.response.GetExtension<ClaimsResponse>();
if (claimsResponse != null) {
this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
}
}
示例12: GetExtraData
/// <summary>
/// Gets the extra data obtained from the response message when authentication is successful.
/// </summary>
/// <param name="response">
/// The response message.
/// </param>
/// <returns>
/// </returns>
protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response) {
FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
if (fetchResponse != null) {
var extraData = new Dictionary<string, string>();
extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
extraData.AddItemIfNotEmpty("fullName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));
return extraData;
}
return null;
}
示例13: GetExtraData
protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
{
var fetchResponse = response.GetExtension<FetchResponse>();
if (fetchResponse != null)
{
var extraData = new Dictionary<string, string>();
extraData.AddItemIfNotEmpty(ClaimTypes.IsPersistent, fetchResponse.GetAttributeValue(ClaimTypes.IsPersistent));
return extraData;
}
return null;
}
示例14: GetFriendlyOpenId
public static string GetFriendlyOpenId(IAuthenticationResponse response, string email)
{
if (response.ClaimedIdentifier.ToString().Contains(WellKnownProviders.Google))
{
return "Google(" + email + ")";
}
if (response.ClaimedIdentifier.ToString().Contains(WellKnownProviders.Yahoo))
{
return "Yahoo(" + email + ")";
}
return response.FriendlyIdentifierForDisplay;
}
示例15: GetExtraData
protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
{
FetchResponse extension = response.GetExtension<FetchResponse>();
if (extension != null)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("email", extension.GetAttributeValue("http://axschema.org/contact/email"));
dictionary.Add("name", extension.GetAttributeValue("http://axschema.org/namePerson/first") + " " + extension.GetAttributeValue("http://axschema.org/namePerson/last"));
return dictionary;
}
return null;
}