/// <summary> /// Validates a user with the PlayFab service /// </summary> public static async Task <PlayFabResult <AuthUserResponse> > AuthUserAsync(AuthUserRequest request, object customData = null, Dictionary <string, string> extraHeaders = null) { if (PlayFabSettings.staticSettings.DeveloperSecretKey == null) { throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must have PlayFabSettings.staticSettings.DeveloperSecretKey set to call this method"); } var httpResult = await PlayFabHttp.DoPost("/Matchmaker/AuthUser", request, "X-SecretKey", PlayFabSettings.staticSettings.DeveloperSecretKey, extraHeaders); if (httpResult is PlayFabError) { var error = (PlayFabError)httpResult; PlayFabSettings.GlobalErrorHandler?.Invoke(error); return(new PlayFabResult <AuthUserResponse> { Error = error, CustomData = customData }); } var resultRawJson = (string)httpResult; var resultData = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <AuthUserResponse> >(resultRawJson); var result = resultData.data; return(new PlayFabResult <AuthUserResponse> { Result = result, CustomData = customData }); }
public (string, AuthUserResponse) AuthUser(AuthUserRequest request) { (string error, User user) = _userRepository.AuthUser(request); var userIdentity = new ClaimsIdentity(); userIdentity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, user.Id.ToString())); if (user.UserLogin == "admin") { userIdentity.AddClaim(new Claim(ClaimsIdentity.DefaultRoleClaimType, "admin")); } else { userIdentity.AddClaim(new Claim(ClaimsIdentity.DefaultRoleClaimType, "user")); } // создаем JWT-токен var jwt = new JwtSecurityToken( issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, notBefore: DateTime.UtcNow, claims: userIdentity.Claims, expires: DateTime.UtcNow.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)), signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); AuthUserResponse response = new AuthUserResponse() { AccessToken = encodedJwt, UserId = userIdentity.Name }; return(error, response); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public async Task <PlayFabResult <AuthUserResponse> > AuthUserAsync(AuthUserRequest request, object customData = null, Dictionary <string, string> extraHeaders = null) { var developerSecretKey = request.AuthenticationContext?.DeveloperSecretKey ?? (authenticationContext?.DeveloperSecretKey ?? PlayFabSettings.DeveloperSecretKey); if (developerSecretKey == null) { throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "DeveloperSecretKey is not found in Request, Server Instance or PlayFabSettings"); } var httpResult = await PlayFabHttp.DoPost("/Matchmaker/AuthUser", request, "X-SecretKey", developerSecretKey, extraHeaders, apiSettings); if (httpResult is PlayFabError) { var error = (PlayFabError)httpResult; PlayFabSettings.GlobalErrorHandler?.Invoke(error); return(new PlayFabResult <AuthUserResponse> { Error = error, CustomData = customData }); } var resultRawJson = (string)httpResult; var resultData = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <AuthUserResponse> >(resultRawJson); var result = resultData.data; return(new PlayFabResult <AuthUserResponse> { Result = result, CustomData = customData }); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public void AuthUser(AuthUserRequest request, Action <AuthUserResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; PlayFabHttp.MakeApiCall("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); }
public AuthUserResponse CreateScreen(AuthUserRequest request) { var response = new AuthUserResponse(); try { response.Success = true; response.Message = null; response.IsAuthed = false; response.CurrentUser = null; //Call the Service Layer BookyService s = new BookyService(); bool isauth = s.AuthenticateUser(request.Username, request.PasswordHash); //todo..create the response..see tb if (isauth) { //Get the user //s.GetUser //response.IsAuthed = true; } //todo get the user object } catch (Exception ex) { response.ErrorCode = ErrorCodes.WebServiceCall; response.Message = ex.Message; response.Success = false; } return(response); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static async Task <PlayFabResult <AuthUserResponse> > AuthUserAsync(AuthUserRequest request, object customData = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } var httpResult = await PlayFabHttp.DoPost("/Matchmaker/AuthUser", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey); if (httpResult is PlayFabError) { var error = (PlayFabError)httpResult; if (PlayFabSettings.GlobalErrorHandler != null) { PlayFabSettings.GlobalErrorHandler(error); } return(new PlayFabResult <AuthUserResponse> { Error = error, CustomData = customData }); } var resultRawJson = (string)httpResult; var resultData = JsonWrapper.DeserializeObject <PlayFabJsonSuccess <AuthUserResponse> >(resultRawJson); var result = resultData.data; return(new PlayFabResult <AuthUserResponse> { Result = result, CustomData = customData }); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static void AuthUser(AuthUserRequest request, Action <AuthUserResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } PlayFabHttp.MakeApiCall("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static void AuthUser(AuthUserRequest request, Action <AuthUserResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } PlayFabHttp.MakeApiCall("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData); }
public AuthUserResponse Authenticate(AuthUserRequest authUserRequest) { if (authUserRequest == null) { throw new NotImplementedException(); } //test git repo return(UserRepository.Authenticate(authUserRequest)); }
/// <summary> /// Internal helper for user auth. /// </summary> private async Task <AddUserResult> AuthUserInternal(AuthUserRequest request, ApiType api, bool isUpdate) { string endpoint = GetEndpoint(api, "step"); HttpResponseMessage response = isUpdate ? await this.httpClient.PatchAsJsonAsync(endpoint, request) : await this.httpClient.PostAsJsonAsync(endpoint, request); return(await this.ProcessAddOrAuthResponse(response)); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public void AuthUser(AuthUserRequest request, Action <AuthUserResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (string.IsNullOrEmpty(callSettings.DeveloperSecretKey)) { throw new PlayFabException(PlayFabExceptionCode.DeveloperKeyNotSet, "Must set DeveloperSecretKey in settings to call this method"); } PlayFabHttp.MakeApiCall("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); }
public IActionResult AuthUser([FromBody] AuthUserRequest request) { (string error, AuthUserResponse response) = _accountService.AuthUser(request); if (!String.IsNullOrEmpty(error)) { return(BadRequest(error)); } return(Ok(response)); }
public async Task <object> Post(AuthUserRequest request) { var authResponse = await _mediator.Send(request); var authFail = authResponse is null; if (authFail) { return(null); } return(_jwtService.CreateJwt(authResponse)); }
/// <inheritdoc /> public Task <AddUserResult> AuthenticateUserAsync(AccessToken accessToken, DeliveryType deliveryType, bool isUpdate = false, ApiType api = ApiType.Connect) { Condition.Requires(accessToken).IsNotNull(); Condition.Requires(deliveryType).IsNotNull(); AuthUserRequest authRequest = new AuthUserRequest(this.clientId, this.clientSecret, accessToken); authRequest.Options = new SendMethodRequest(); authRequest.Options.SendMethod = new ExpandoObject(); authRequest.Options.SendMethod.type = deliveryType.Value; return(this.AuthUserInternal(authRequest, api, isUpdate)); }
/// <inheritdoc /> public Task <AddUserResult> AuthenticateUserAsync(AccessToken accessToken, string deviceMask, bool isUpdate = false, ApiType api = ApiType.Connect) { Condition.Requires(accessToken).IsNotNull(); Condition.Requires(deviceMask).IsNotNullOrWhiteSpace(); AuthUserRequest authRequest = new AuthUserRequest(this.clientId, this.clientSecret, accessToken); authRequest.Options = new SendMethodRequest(); authRequest.Options.SendMethod = new ExpandoObject(); authRequest.Options.SendMethod.mask = deviceMask; return(this.AuthUserInternal(authRequest, api, isUpdate)); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> /// <param name="AuthorizationTicket">Session Ticket provided by the client. (Required)</param> public static Task <AuthUserResponse> AuthUser(string AuthorizationTicket, PlayFabAuthenticationContext customAuthContext = null, object customData = null, Dictionary <string, string> extraHeaders = null) { AuthUserRequest request = new AuthUserRequest() { AuthorizationTicket = AuthorizationTicket, }; var context = GetContext(customAuthContext); return(PlayFabHttp.MakeApiCallAsync <AuthUserResponse>("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, customData, extraHeaders, context)); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static void AuthUser(AuthUserRequest request, ProcessApiCallback <AuthUserResponse> resultCallback, ErrorCallback errorCallback, object customData = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy); Action <CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { ResultContainer <AuthUserResponse> .HandleResults(requestContainer, resultCallback, errorCallback, null); }; PlayFabHTTP.Post("/Matchmaker/AuthUser", serializedJson, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, callback, request, customData); }
public ActionResult Login(AuthUserRequest request) { var userFounded = this._service.Login(request.Username, request.Password); if (userFounded == null) { return(Unauthorized()); } String token = GenerateToken(userFounded); return(Ok(new AuthUserResponse() { User = userFounded, Token = token })); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { IServiceUser serviceUser = _container.Resolve <IServiceUser>(); AuthUserRequest request = new AuthUserRequest(); request.Email = context.UserName; request.Password = context.Password; AuthUserResponse response = serviceUser.AuthUser(request); if (serviceUser.IsInvalid()) { if (response == null) { context.SetError("invalid_grant", Message.X0_IsInvalid.ToFormat(Message.Email + Message.Or + Message.Password)); return; } } serviceUser.ClearNotifications(); if (response == null) { context.SetError("invalid_grant", Message.DataNotFound); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); //Definindo as Claims identity.AddClaim(new Claim("GTUser", JsonConvert.SerializeObject(response))); var principal = new GenericPrincipal(identity, new string[] { }); Thread.CurrentPrincipal = principal; context.Validated(identity); } catch (Exception ex) { context.SetError("invalid_grant", ex.Message); return; } }
/// <inheritdoc /> public Task <AddUserResult> AuthenticateUserAsync(AccessToken accessToken, bool isUpdate = false, ApiType api = ApiType.Connect, params string[] mfaValues) { Condition.Requires(accessToken).IsNotNull(); Condition.Requires(mfaValues).IsNotNull().IsNotEmpty(); AuthUserRequest authRequest = new AuthUserRequest(this.clientId, this.clientSecret, accessToken); if (mfaValues.Length == 1) { authRequest.MfaValue = mfaValues.FirstOrDefault(); } else { authRequest.MfaValue = new List <string>(mfaValues); } return(this.AuthUserInternal(authRequest, api, isUpdate)); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static void AuthUser(AuthUserRequest request, AuthUserCallback resultCallback, ErrorCallback errorCallback, object customData = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } string serializedJson = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings); Action <CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { AuthUserResponse result = ResultContainer <AuthUserResponse> .HandleResults(requestContainer, resultCallback, errorCallback); if (result != null) { } }; PlayFabHTTP.Post("/Matchmaker/AuthUser", serializedJson, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, callback, request, customData); }
// Сделать логины дивидуальными public (string, User) AuthUser(AuthUserRequest request) { try { var user = _context.Users.ToList() .FirstOrDefault(u => u.UserLogin == request.Login && u.UserPassword == request.Password); if (user != null) { return(null, user); } return("Wrong password", null); } catch (Exception e) { return(e.Message, null); } }
private static string GetToken() { AuthUserRequest aurequest = new AuthUserRequest() { Login = "******", Password = "******" }; string jsonString = JsonConvert.SerializeObject(aurequest); using (var client = new HttpClient()) { var response = client.PostAsync( "https://photoapimsp.azurewebsites.net/api/Security/", new StringContent(jsonString, Encoding.UTF8, "application/json")); string str = response.Result.Content.ReadAsStringAsync().GetAwaiter().GetResult(); AuthUserResponse auresponse = JsonConvert.DeserializeObject <AuthUserResponse>(str); return(auresponse.AccessToken); } }
public AuthUserResponse AuthUser(AuthUserRequest request) { //TODO mudar mensagem if (request == null) { AddNotification("AuthUserRequest", Message.X0_IsRequired.ToFormat("AuthUserRequest")); } var email = new Email(request.Email); var authUser = new GTUser(email, request.Password); AddNotifications(authUser, email); if (IsInvalid()) { return(null); } authUser = _repositorieUser.GetBy(o => o.Email.Adress == authUser.Email.Adress && o.Password == authUser.Password); return((AuthUserResponse)authUser); }
/// <summary> /// Validates a user with the PlayFab service /// </summary> public static void AuthUser(AuthUserRequest request, Action <AuthUserResponse> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null) { PlayFabHttp.MakeApiCall("/Matchmaker/AuthUser", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData, extraHeaders); }