|
|
|
@ -5,10 +5,10 @@ |
|
|
|
// All rights reserved. Licensed under the MIT license.
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authentication.OAuth; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Shared.Identity; |
|
|
|
|
|
|
|
namespace Squidex.Config.Authentication |
|
|
|
@ -17,27 +17,11 @@ namespace Squidex.Config.Authentication |
|
|
|
{ |
|
|
|
public override Task CreatingTicket(OAuthCreatingTicketContext context) |
|
|
|
{ |
|
|
|
var displayNameClaim = context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name); |
|
|
|
if (displayNameClaim != null) |
|
|
|
{ |
|
|
|
context.Identity.SetDisplayName(displayNameClaim.Value); |
|
|
|
} |
|
|
|
|
|
|
|
var pictureUrl = context.User?.Value<string>("picture"); |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(pictureUrl)) |
|
|
|
{ |
|
|
|
pictureUrl = context.User?["image"]?.Value<string>("url"); |
|
|
|
|
|
|
|
if (pictureUrl != null && pictureUrl.EndsWith("?sz=50", System.StringComparison.Ordinal)) |
|
|
|
{ |
|
|
|
pictureUrl = pictureUrl.Substring(0, pictureUrl.Length - 6); |
|
|
|
} |
|
|
|
} |
|
|
|
var nameClaim = context.Identity.FindFirst(ClaimTypes.Name)?.Value; |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(pictureUrl)) |
|
|
|
if (!string.IsNullOrWhiteSpace(nameClaim)) |
|
|
|
{ |
|
|
|
context.Identity.SetPictureUrl(pictureUrl); |
|
|
|
context.Identity.SetDisplayName(nameClaim); |
|
|
|
} |
|
|
|
|
|
|
|
return base.CreatingTicket(context); |
|
|
|
|