Skip to content
Browse files

Merge pull request #518 from pdegenhardt/master

Improve name handling from OpenID 2.0 sources
  • Loading branch information...
2 parents 9a9cedb + 8c198fd commit 69a45c32dbc656c41bcbe1b319802ffe998f3a3e @mythz mythz committed Mar 14, 2013
Showing with 12 additions and 7 deletions.
  1. +12 −7 src/ServiceStack.Authentication.OpenId/OpenIdOAuthProvider.cs
View
19 src/ServiceStack.Authentication.OpenId/OpenIdOAuthProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
@@ -227,17 +228,18 @@ private void AddAttributeExchangeExtensions(IAuthenticationRequest auth)
if (fetchResponse == null) return ret;
+ string fullName = null;
var names = new List<string>();
var emails = new List<string>();
if (fetchResponse.Attributes.Contains("http://schema.openid.net/namePerson"))
- names.AddRange(fetchResponse.Attributes["http://schema.openid.net/namePerson"].Values);
+ fullName = fetchResponse.Attributes["http://schema.openid.net/namePerson"].Values.FirstOrDefault();
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.FullName))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.FullName].Values);
+ if (fullName == null && fetchResponse.Attributes.Contains(WellKnownAttributes.Name.FullName))
+ fullName = fetchResponse.Attributes[WellKnownAttributes.Name.FullName].Values.FirstOrDefault();
- if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Alias))
- names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.Alias].Values);
+ if (fullName == null && fetchResponse.Attributes.Contains(WellKnownAttributes.Name.Alias))
+ fullName = fetchResponse.Attributes[WellKnownAttributes.Name.Alias].Values.FirstOrDefault();
if (fetchResponse.Attributes.Contains(WellKnownAttributes.Name.First))
names.AddRange(fetchResponse.Attributes[WellKnownAttributes.Name.First].Values);
@@ -251,8 +253,11 @@ private void AddAttributeExchangeExtensions(IAuthenticationRequest auth)
if (fetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email))
emails.AddRange(fetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values);
- if (names.Count > 0)
- ret["FullName"] = names[0];
+ if (fullName == null && names.Count > 0)
+ fullName = string.Join(" ", names.ToArray());
+
+ if (fullName != null)
+ ret["FullName"] = fullName;
if (emails.Count > 0)
ret["Email"] = emails[0];

0 comments on commit 69a45c3

Please sign in to comment.
Something went wrong with that request. Please try again.