-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Web/Masa.Auth.Web.Sso/Infrastructure/Validations/PssoPhoneCodeGrantValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Web.Sso.Infrastructure.Validations; | ||
|
||
public class PssoPhoneCodeGrantValidator : IExtensionGrantValidator | ||
{ | ||
IAuthClient _authClient; | ||
|
||
public string GrantType { get; } = BuildingBlocks.Authentication.OpenIdConnect.Models.Constans.GrantType.PSSO_PHONE_CODE; | ||
|
||
public PssoPhoneCodeGrantValidator(IAuthClient authClient) | ||
{ | ||
_authClient = authClient; | ||
} | ||
|
||
public async Task ValidateAsync(ExtensionGrantValidationContext context) | ||
{ | ||
var phoneNumber = context.Request.Raw["PhoneNumber"]; | ||
var code = context.Request.Raw["Code"]; | ||
if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(code)) | ||
throw new UserFriendlyException("must provider phone number and msg code"); | ||
|
||
var user = await _authClient.UserService.LoginByPhoneNumberAsync(new LoginByPhoneNumberModel | ||
{ | ||
PhoneNumber = phoneNumber, | ||
Code = code | ||
}); | ||
if (user != null) | ||
{ | ||
var authUser = await _authClient.UserService.GetThirdPartyUserByUserIdAsync(new GetThirdPartyUserByUserIdModel | ||
{ | ||
Scheme = "Psso", | ||
UserId = user.Id | ||
}); | ||
|
||
var claims = new List<Claim>(); | ||
if (authUser != null) | ||
{ | ||
foreach (var item in authUser.ClaimData) | ||
{ | ||
claims.Add(new Claim(item.Key, item.Value)); | ||
} | ||
} | ||
|
||
context.Result = new GrantValidationResult(user.Id.ToString(), "sms", claims); | ||
} | ||
else | ||
{ | ||
context.Result = new GrantValidationResult( | ||
TokenRequestErrors.InvalidGrant, | ||
"invalid custom credential"); | ||
} | ||
|
||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
src/Web/Masa.Auth.Web.Sso/Infrastructure/Validations/PssoPhoneNumberGrantValidator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters