本文整理汇总了C#中IAuthenticationResponse.GetExtension方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticationResponse.GetExtension方法的具体用法?C# IAuthenticationResponse.GetExtension怎么用?C# IAuthenticationResponse.GetExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthenticationResponse
的用法示例。
在下文中一共展示了IAuthenticationResponse.GetExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: 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;
}
示例3: 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);
}
}
}
示例4: OpenIdAuthenticationParameters
public OpenIdAuthenticationParameters(IAuthenticationResponse authenticationResponse)
{
ExternalIdentifier = authenticationResponse.ClaimedIdentifier;
ExternalDisplayIdentifier = authenticationResponse.FriendlyIdentifierForDisplay;
_claims = new List<UserClaims>();
var claimsResponseTranslator = new OpenIdClaimsResponseClaimsTranslator();
var claims1 = claimsResponseTranslator.Translate(authenticationResponse.GetExtension<ClaimsResponse>());
if (claims1 != null)
UserClaims.Add(claims1);
var fetchResponseTranslator = new OpenIdFetchResponseClaimsTranslator();
var claims2 = fetchResponseTranslator.Translate(authenticationResponse.GetExtension<FetchResponse>());
if (claims2 != null)
UserClaims.Add(claims2);
}
示例5: 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;
}
示例6: SetUserInformationGeneric
private void SetUserInformationGeneric(IAuthenticationResponse response)
{
var userdata = response.GetExtension<ClaimsResponse>();
var email = userdata.Email;
FullName = userdata.FullName;
Email = email;
}
示例7: 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);
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: GetUserIdentity
private Interfaces.IAuthenticationResponse GetUserIdentity(IAuthenticationResponse response)
{
var identifier = response.ClaimedIdentifier;
var fetch = response.GetExtension<FetchResponse>();
Interfaces.IUserIdentity userIdentity = (fetch == null)
? null
: Factory.GetUserIdentity(response.ClaimedIdentifier.ToString(),
fetch.GetAttributeValue(WellKnownAttributes.Name.First),
fetch.GetAttributeValue(WellKnownAttributes.Name.Last),
fetch.GetAttributeValue(WellKnownAttributes.Contact.Email));
return Factory.AuthenticationResponse(userIdentity);
}
示例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>A dictionary of profile data; or null if no data is available.</returns>
protected override NameValueCollection GetExtraData(IAuthenticationResponse response) {
FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
if (fetchResponse != null) {
var extraData = new NameValueCollection();
extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
extraData.AddItemIfNotEmpty("country", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.HomeAddress.Country));
extraData.AddItemIfNotEmpty("firstName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.First));
extraData.AddItemIfNotEmpty("lastName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Last));
return extraData;
}
return null;
}
示例13: LogInMember
/// <summary>
/// Log member in from response informations.
/// </summary>
/// <param name="response">A successfull response from the relying party</param>
public void LogInMember(IAuthenticationResponse response)
{
var fetch = response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
string email = null;
if (fetch != null)
{
email = fetch.Email;
}
Member connectedMember = email == null
? _membershipService.LogIn(response.ClaimedIdentifier.ToString())
: _membershipService.LogIn(response.ClaimedIdentifier.ToString(), email);
_sessionRegistry.MemberInformations.UserName = connectedMember.UserName;
_sessionRegistry.MemberInformations.OpenId = response.ClaimedIdentifier.ToString();
}
示例14: ResponseIntoUser
public OpenIdUser ResponseIntoUser(IAuthenticationResponse response)
{
var claimResponseUntrusted = response.GetUntrustedExtension<ClaimsResponse>();
var claimResponse = response.GetExtension<ClaimsResponse>();
if (claimResponse != null)
{
return new OpenIdUser(claimResponse, response.ClaimedIdentifier);
}
if (claimResponseUntrusted != null)
{
return new OpenIdUser(claimResponseUntrusted, response.ClaimedIdentifier);
}
return null;
}
示例15: FetchEmail
private static string FetchEmail(IAuthenticationResponse response)
{
var fetch = response.GetExtension<FetchResponse>();
string email = string.Empty;
if (fetch != null)
{
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
if (string.IsNullOrEmpty(email))
{
throw new InvalidOperationException("Email is required, but was not supplied by the OpenID provider.");
}
return email;
}