public virtual void AssociateExternalAccountWithUser(Customer customer, OpenAuthenticationParameters parameters) { if (customer == null) throw new ArgumentNullException("customer"); //find email string email = null; if (parameters.UserClaims != null) foreach (var userClaim in parameters.UserClaims .Where(x => x.Contact != null && !String.IsNullOrEmpty(x.Contact.Email))) { //found email = userClaim.Contact.Email; break; } var externalAuthenticationRecord = new ExternalAuthenticationRecord() { CustomerId = customer.Id, Email = email, ExternalIdentifier = parameters.ExternalIdentifier, ExternalDisplayIdentifier = parameters.ExternalDisplayIdentifier, OAuthToken = parameters.OAuthToken, OAuthAccessToken = parameters.OAuthAccessToken, ProviderSystemName = parameters.ProviderSystemName, }; _externalAuthenticationRecordRepository.Insert(externalAuthenticationRecord); }
public void Can_save_and_load_externalAuthenticationRecord() { var externalAuthenticationRecord = new ExternalAuthenticationRecord { Email = "Email 1", ExternalIdentifier = "ExternalIdentifier 1", ExternalDisplayIdentifier = "ExternalDisplayIdentifier 1", OAuthToken = "OAuthToken 1", OAuthAccessToken = "OAuthAccessToken 1", ProviderSystemName = "ProviderSystemName 1", Customer = GetTestCustomer() }; var fromDb = SaveAndLoadEntity(externalAuthenticationRecord); fromDb.ShouldNotBeNull(); fromDb.Email.ShouldEqual("Email 1"); fromDb.ExternalIdentifier.ShouldEqual("ExternalIdentifier 1"); fromDb.ExternalDisplayIdentifier.ShouldEqual("ExternalDisplayIdentifier 1"); fromDb.OAuthToken.ShouldEqual("OAuthToken 1"); fromDb.OAuthAccessToken.ShouldEqual("OAuthAccessToken 1"); fromDb.ProviderSystemName.ShouldEqual("ProviderSystemName 1"); fromDb.Customer.ShouldNotBeNull(); }