//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.AspNet.Clients {
using System.Collections.Generic;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.RelyingParty;
///
/// Represents Google OpenID client.
///
public sealed class GoogleOpenIdClient : OpenIdClient {
#region Constructors and Destructors
///
/// Initializes a new instance of the class.
///
public GoogleOpenIdClient()
: base("google", WellKnownProviders.Google) { }
#endregion
#region Methods
///
/// Gets the extra data obtained from the response message when authentication is successful.
///
///
/// The response message.
///
/// A dictionary of profile data; or null if no data is available.
protected override Dictionary GetExtraData(IAuthenticationResponse response) {
FetchResponse fetchResponse = response.GetExtension();
if (fetchResponse != null) {
var extraData = new Dictionary();
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;
}
///
/// Called just before the authentication request is sent to service provider.
///
///
/// The request.
///
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);
}
#endregion
}
}