public IHttpActionResult Post([FromBody] CreateTokenModel model) { using (var t = Repository.BeginTransaction()) { var authToken = AuthTokenService.Create(model.Username, model.Password); t.Commit(); return(Json(Mapper.Map <AuthTokenCreateView>(authToken))); } }
public AuthController( UserManager <User> userManager, AuthTokenService tokenService, AvatarsService avatarsService, IMapper mapper ) { _userManager = userManager; _tokenService = tokenService; _avatarsService = avatarsService; _mapper = mapper; }
public AccountController( UserManager <User> userManager, AuthTokenService tokenService, AccountService accountService, IMapper mapper, ICurrentUserAccessor currentUser) { _userManager = userManager; _currentUser = currentUser; _tokenService = tokenService; _accountService = accountService; _mapper = mapper; }
public void Login_Should_ReturnReadableToken() { // Arrange var tokenService = new AuthTokenService(); var sut = new AuthService(tokenService); var req = new LoginRequest { Email = "*****@*****.**", Password = "******", Provider = "MyCars" }; // Act var result = sut.Login(req); // Assert var handler = new JwtSecurityTokenHandler(); Assert.True(handler.CanReadToken(result)); }
private static void ValidateBasicAuthentication() { string authorization = WebOperationContext.Current?.IncomingRequest.Headers[ContextConstant.HeaderAuthorizationName]; if (string.IsNullOrWhiteSpace(authorization)) { throw new UnauthorizedTokenException("未认证身份信息"); //throw new WebFaultException(HttpStatusCode.Forbidden); } BasicAuth basicAuth = new BasicAuth(authorization); ReturnMessage <string> ret = new AuthTokenService().Authenticate(basicAuth.Creds); ValidateToken(ret.Result); }
public static IApplicationBuilder UseGetuiServiceApi(this IApplicationBuilder applicationBuilder, IServiceProvider serviceProvider) { AuthTokenService authTokenService = serviceProvider.GetService <AuthTokenService>(); GetuiConfiguration getuiConfiguration = serviceProvider.GetService <GetuiConfiguration>(); if (getuiConfiguration == null) { throw new ArgumentNullException(nameof(GetuiConfiguration)); } //提前获取auto token防止启动时候的并发发送 Task.Run(async() => { await authTokenService.GetAuthToken(); }); return(applicationBuilder); }
public AuthController(AuthTokenService authToken) { this.authToken = authToken; }
public ReturnMessage <string> Login(Credentials cred) { AuthTokenService authTokenService = new AuthTokenService(); return(authTokenService.Authenticate(cred)); }
public AuthorizationHandler(AuthTokenService authTokenS, IHttpContextAccessor httpContextAccessor) { authTokenService = authTokenS; _httpContextAccessor = httpContextAccessor; }