This commit is contained in:
2019-10-08 23:41:19 +01:00
parent 7407f08223
commit 0fc8f53a14
18 changed files with 102 additions and 80 deletions

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.DataProtection;
using Microsoft.AspNet.Identity;
using Yavsc.Models;
using Yavsc.Server;
namespace Yavsc.Auth {
@ -22,14 +23,14 @@ namespace Yavsc.Auth {
public Task<string> GenerateAsync(string purpose, UserManager<ApplicationUser> manager, ApplicationUser user)
{
if ( user==null ) throw new InvalidOperationException("no user");
var por = new MonoDataProtector(Constants.ApplicationName,new string[] { purpose } );
var por = new MonoDataProtector(ServerConstants.ApplicationName, new string[] { purpose } );
return Task.FromResult(por.Protect(UserStamp(user)));
}
public Task<bool> ValidateAsync(string purpose, string token, UserManager<ApplicationUser> manager, ApplicationUser user)
{
var por = new MonoDataProtector(Constants.ApplicationName,new string[] { purpose } );
var por = new MonoDataProtector(ServerConstants.ApplicationName,new string[] { purpose } );
var userStamp = por.Unprotect(token);
Console.WriteLine ("Unprotected: "+userStamp);
string [] values = userStamp.Split(';');
@ -40,4 +41,4 @@ namespace Yavsc.Auth {
return $"{user.Id};{user.Email};{user.UserName}";
}
}
}
}