mirror of https://github.com/abpframework/abp.git
10 changed files with 97 additions and 12 deletions
@ -1,18 +1,43 @@ |
|||
using System.Threading.Tasks; |
|||
using System.IO; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using IdentityModel; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.IdentityModel; |
|||
using Volo.Abp.IO; |
|||
|
|||
namespace Volo.Abp.Cli.Auth |
|||
{ |
|||
public class AuthService : ITransientDependency |
|||
{ |
|||
protected IIdentityModelAuthenticationService AuthenticationService { get; } |
|||
|
|||
public AuthService(IIdentityModelAuthenticationService authenticationService) |
|||
{ |
|||
AuthenticationService = authenticationService; |
|||
} |
|||
|
|||
public async Task LoginAsync(string userName, string password) |
|||
{ |
|||
var accessToken = await AuthenticationService.GetAccessTokenAsync( |
|||
new IdentityClientConfiguration( |
|||
"https://localhost:44333", //TODO: Configure
|
|||
"role email abpio_www", |
|||
"abp-cli", |
|||
"1q2w3e*", |
|||
OidcConstants.GrantTypes.Password, |
|||
userName, |
|||
password |
|||
) |
|||
); |
|||
|
|||
File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8); |
|||
} |
|||
|
|||
public async Task LogoutAsync() |
|||
public Task LogoutAsync() |
|||
{ |
|||
|
|||
FileHelper.DeleteIfExists(CliPaths.AccessToken); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.Cli.Utils |
|||
{ |
|||
public static class ConsoleHelper |
|||
{ |
|||
public static string ReadSecret() |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
|
|||
while (true) |
|||
{ |
|||
var keyInfo = Console.ReadKey(true); |
|||
if (keyInfo.Key == ConsoleKey.Enter) |
|||
{ |
|||
break; |
|||
} |
|||
|
|||
sb.Append(keyInfo.KeyChar); |
|||
} |
|||
|
|||
return sb.ToString(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue