public SigninViewModel() { _navigationService = new NavigationService(); _authenticatorService = new AuthenticatorService(); Model = new CreateUserBindingModel { Username = "******", Password = "******", ConfirmPassword = "******", Email = "[email protected]", FirstName = "Test1", LastName = "User1", //RoleName = "" }; if (!string.IsNullOrEmpty(Settings.Username)) { Model.Username = Settings.Username; } if (!string.IsNullOrEmpty(Settings.Email)) { Model.Email = Settings.Email; } if (!string.IsNullOrEmpty(Settings.Password)) { Model.Password = Settings.Password; } }
public IActionResult Authenticate([FromBody] UserLogin logInfo) { if (logInfo is null) { return(BadRequest(new { error = "No login given" })); } var user = AuthenticatorService.Authenticate(logInfo); if (user is null) { return(BadRequest(new { error = "invalid credentials no user found." })); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.UTF8.GetBytes(Secret); var tokenDescriptor = new SecurityTokenDescriptor() { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, logInfo.Username), new Claim(ClaimTypes.Role, "User") }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); return(Ok(new { UserName = logInfo.Username, Token = tokenString })); }
public void GetCodeBadHashAlgotithm() { var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); Assert.Throws <ArgumentException>(() => service.GetCode((HashAlgorithmType)100, Encoding.UTF8.GetBytes("test"), 8, 30)); }
public OAuth2Authenticator GetAuthenticator(AuthenticatorType type, Action <string> tokenCallBack) { var authenticator = AuthenticatorService.GetAuthenticator(type, (acct) => { if (acct != null) { Console.WriteLine($"**************************** {acct.Properties["access_token"]} *****************************"); tokenCallBack?.Invoke(acct.Properties["access_token"]); } else { Console.WriteLine($"**************************** Account was NULL *****************************"); tokenCallBack?.Invoke("Token was null"); } if (Xamarin.Forms.Device.RuntimePlatform == "iOS") { DependencyService.Get <IViewStack>().DismissTopView(); } }, (error) => { Log.LogException(error); tokenCallBack?.Invoke(error.Message); }); AuthenticationState.Authenticator = authenticator; return(authenticator); }
public AuthenticatorDroid() { var platformParameters = new PlatformParameters((Activity)Forms.Context, false, PromptBehavior.Auto); _authenticatorService = new AuthenticatorService(platformParameters); }
public void GetUriSuccess(HashAlgorithmType hashAlgorithm, byte period, byte digits) { var id = Guid.NewGuid().ToString(); var secret = new byte[32]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(secret); } var options = GetOptions(); options.Value.HashAlgorithm = hashAlgorithm; options.Value.NumberOfDigits = digits; options.Value.PeriodInSeconds = period; var service = new AuthenticatorService(options, new DefaultSystemTime()); var uri = service.GetUri(id, secret); Assert.Equal(string.Format("otpauth://totp/{0}%3A{1}?secret={2}&issuer={0}&algorithm={3}&digits={4}&period={5}", Issuer, id, Base32Encoding.Encode(secret).Trim('='), hashAlgorithm.ToString(), digits, period ), uri); }
public void GetCodeInvalidPeriodInSeconds(byte periodInSeconds) { var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); var ex = Assert.Throws <ArgumentException>(() => service.GetCode(HashAlgorithmType.SHA1, Encoding.UTF8.GetBytes("12345678901234567890"), 6, periodInSeconds)); Assert.Equal("The period must be at least 30 seconds.", ex.Message); }
public void GetCodeInvalidNumberOfDigits(byte numberOfDigit) { var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); var ex = Assert.Throws <ArgumentException>(() => service.GetCode(HashAlgorithmType.SHA1, Encoding.UTF8.GetBytes("12345678901234567890"), numberOfDigit, 30)); Assert.Equal("The number of digits must be between 6 and 8.", ex.Message); }
public AuthenticatoriOS() { var platformParameters = new PlatformParameters(UIApplication .SharedApplication .KeyWindow.RootViewController, false, PromptBehavior.Auto); _authenticatorService = new AuthenticatorService(platformParameters); }
public void GetPeriodInSeconds(byte periodInSeconds) { var options = GetOptions(); options.Value.PeriodInSeconds = periodInSeconds; var service = new AuthenticatorService(options, new DefaultSystemTime()); Assert.Equal(periodInSeconds, service.PeriodInSeconds); }
public ServiceCore(IScheduler scheduler, AuthenticatorService authenticatorService) { if (scheduler == null) { throw new ArgumentNullException(nameof(scheduler)); } _scheduler = scheduler; _authenticatorService = authenticatorService; }
public void GetHashAlgorithm(HashAlgorithmType hashAlgorithm) { var options = GetOptions(); options.Value.HashAlgorithm = hashAlgorithm; var service = new AuthenticatorService(options, new DefaultSystemTime()); Assert.Equal(hashAlgorithm, service.HashAlgorithm); }
public void GetNumberOfDigits(byte numberOfDigits) { var options = GetOptions(); options.Value.NumberOfDigits = numberOfDigits; var service = new AuthenticatorService(options, new DefaultSystemTime()); Assert.Equal(numberOfDigits, service.NumberOfDigits); }
public void GetUriNullSecret() { var id = Guid.NewGuid().ToString(); byte[] secret = null; var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); var ex = Assert.Throws <ArgumentNullException>(() => service.GetUri(id, secret)); }
public void GetUriNullUserId() { var secret = new byte[32]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(secret); } var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); var ex = Assert.Throws <ArgumentNullException>(() => service.GetUri(null, secret)); }
public void GetUriNullBadHashAlgotithm() { var id = Guid.NewGuid().ToString(); var secret = new byte[32]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(secret); } var options = GetOptions(); options.Value.HashAlgorithm = (HashAlgorithmType)100; var service = new AuthenticatorService(options, new DefaultSystemTime()); var ex = Assert.Throws <ArgumentException>(() => service.GetUri(id, secret)); }
public void GetCodeTest(long time, int expectedCode, HashAlgorithmType hashAlgorithm, string secret) { //https://tools.ietf.org/html/rfc6238#appendix-B var systemTime = new Mock <ISystemTime>(MockBehavior.Strict); systemTime .Setup(a => a.GetUtcNow()) .Returns(UnixEpoch.AddSeconds(time)) .Verifiable(); var options = GetOptions(); var service = new AuthenticatorService(options, systemTime.Object); var code = service.GetCode(hashAlgorithm, Encoding.UTF8.GetBytes(secret), 8, 30); Assert.Equal(expectedCode, code); systemTime.Verify(); }
} //Single instance. Will handle refresh token.. protected BaseJob(IActionContext actionContext, AuthenticatorService authenticatorService) { ActionContext = actionContext; AuthenticatorService = authenticatorService; }
public HeartbeatJob(IHeartbeatService hearbeat, IActionContext actionContext, AuthenticatorService authenticatorService) : base(actionContext, authenticatorService) { if (hearbeat == null) { throw new ArgumentNullException(nameof(hearbeat)); } _hearbeat = hearbeat; }
public AuthController(AuthenticatorService userAuth) { _userAuth = userAuth; }
public void Success() { var options = GetOptions(); var service = new AuthenticatorService(options, new DefaultSystemTime()); }
public TwoFactorAuthenticationController(AuthenticatorService authenticatorService, UserManager <AppUser> userManager, SignInManager <AppUser> signInManager) { _authenticatorService = authenticatorService; _userManager = userManager; _signInManager = signInManager; }