public async Task <AuthenticationResult> Authenticate(AuthenticationContext authenticationCtx, CancellationToken ct) { var pId = new PlatformId { Platform = PROVIDER_NAME }; if (!authenticationCtx.Parameters.TryGetValue("login", out var login)) { return(AuthenticationResult.CreateFailure("loginPassword.login.missingArgument?id=login", pId, authenticationCtx.Parameters)); } if (!authenticationCtx.Parameters.TryGetValue("password", out var password)) { return(AuthenticationResult.CreateFailure("loginPassword.login.missingArgument?id=password", pId, authenticationCtx.Parameters)); } pId.OnlineId = login; var user = await users.GetUserByClaim(PROVIDER_NAME, ClaimPath + ".login", login); if (user == null) { return(AuthenticationResult.CreateFailure("loginPassword.login.invalidCredentials", pId, authenticationCtx.Parameters)); } var authParams = user.Auth[ClaimPath]?.ToObject <LoginPasswordAuthRecord>(); var derivedKey = DeriveKey(password, authParams.iterations, authParams.salt, new HashAlgorithmName(authParams.algorithm)); if (!BytesEqual(derivedKey, authParams.derivedKey)) { return(AuthenticationResult.CreateFailure("loginPassword.login.invalidCredentials", pId, authenticationCtx.Parameters)); } return(AuthenticationResult.CreateSuccess(user, pId, authenticationCtx.Parameters)); }
public async Task <AuthenticationResult> Authenticate(AuthenticationContext authenticationCtx, CancellationToken ct) { var pId = new PlatformId { Platform = PROVIDER_NAME }; string identifier; if (!authenticationCtx.Parameters.TryGetValue("deviceidentifier", out identifier)) { return(AuthenticationResult.CreateFailure("Device identifier must not be empty.", pId, authenticationCtx.Parameters)); } var user = await _users.GetUserByClaim(PROVIDER_NAME, ClaimPath, identifier); if (user == null) { var uid = Guid.NewGuid().ToString("N"); user = await _users.CreateUser(uid, JObject.FromObject(new { deviceidentifier = identifier })); user = await _users.AddAuthentication(user, PROVIDER_NAME, claim => claim[ClaimPath] = identifier, new Dictionary <string, string> { { ClaimPath, identifier } }); } pId.OnlineId = user.Id; return(AuthenticationResult.CreateSuccess(user, pId, authenticationCtx.Parameters)); }
/// <summary> /// Get the player session from the active authenticator scene (returns null for players authenticated on an older deployment. /// </summary> /// <param name="platformId"></param> /// <returns></returns> public async Task <Session> GetSession(PlatformId platformId, bool forceRefresh) { var response = await AuthenticatorRpc(null, "usersession.getsessionbyplatformid", s => _serializer.Serialize(platformId, s)); using (response.Stream) { var result = _serializer.Deserialize <Session>(response.Stream); return(result); } }
public async Task <string> GetDisplayableUserId(PlatformId platformId) { var service = GetServiceForPlatform(platformId.Platform); if (service != null) { return(await service.GetDisplayableUserId(platformId)); } else { return(null); } }
public async Task Setup(Dictionary <string, string> parameters) { var pId = new PlatformId { Platform = PROVIDER_NAME }; if (!parameters.TryGetValue("login", out var login)) { throw new ClientException("auth.loginPassword.create.missingParameter?id=login"); } if (!parameters.TryGetValue("password", out var password)) { throw new ClientException("auth.loginPassword.create.missingParameter?id=password"); } pId.OnlineId = login; var user = await users.GetUserByClaim(PROVIDER_NAME, ClaimPath + ".login", login); if (user != null) { throw new ClientException("auth.loginPassword.create.accountAlreadyExist"); } if (user == null) { var uid = Guid.NewGuid().ToString("N"); user = await users.CreateUser(uid, JObject.FromObject(new { login = login })); var hash = DeriveKey(password, out var iterations, out var salt, out var algorithm); user = await users.AddAuthentication(user, PROVIDER_NAME, claim => { claim[ClaimPath] = JObject.FromObject(new LoginPasswordAuthRecord { login = login, salt = salt, iterations = iterations, algorithm = algorithm.Name, derivedKey = hash }); }, new Dictionary <string, string> { { ClaimPath, login } }); } }
public async Task <AuthenticationResult> Authenticate(AuthenticationContext authenticationCtx, CancellationToken ct) { var pId = new PlatformId { Platform = Provider_Name }; if (!authenticationCtx.Parameters.TryGetValue("secret", out string secret) || string.IsNullOrWhiteSpace(secret)) { return(AuthenticationResult.CreateFailure("Missing impersonation secret.", pId, authenticationCtx.Parameters)); } if (secret != _secret) { return(AuthenticationResult.CreateFailure("Invalid impersonation secret.", pId, authenticationCtx.Parameters)); } if (!authenticationCtx.Parameters.TryGetValue("impersonated-provider", out string ImpersonatingProvider) || string.IsNullOrWhiteSpace(ImpersonatingProvider)) { return(AuthenticationResult.CreateFailure("'impersonated-provider' must not be empty.", pId, authenticationCtx.Parameters)); } if (!authenticationCtx.Parameters.TryGetValue("claimPath", out string ImpersonatingClaimPath) || string.IsNullOrWhiteSpace(ImpersonatingClaimPath)) { return(AuthenticationResult.CreateFailure("'claimPath' must not be empty.", pId, authenticationCtx.Parameters)); } if (!authenticationCtx.Parameters.TryGetValue("claimValue", out string ImpersonatingClaimValue) || string.IsNullOrWhiteSpace(ImpersonatingClaimValue)) { return(AuthenticationResult.CreateFailure("'claimValue' must not be empty.", pId, authenticationCtx.Parameters)); } var user = await _users.GetUserByClaim(ImpersonatingProvider, ImpersonatingClaimPath, ImpersonatingClaimValue); if (user == null) { return(AuthenticationResult.CreateFailure($"The user '{ImpersonatingProvider}/{ImpersonatingClaimPath} = {ImpersonatingClaimValue}' does not exist.", pId, authenticationCtx.Parameters)); } else { return(AuthenticationResult.CreateSuccess(user, new PlatformId { Platform = ImpersonatingProvider, OnlineId = ImpersonatingClaimValue }, authenticationCtx.Parameters)); } }
public async Task Login(IScenePeerClient peer, User user, PlatformId onlineId) { if (peer == null) { throw new ArgumentNullException("peer"); } if (user == null) { throw new ArgumentNullException("user"); } bool added = false; while (!added) { var r = await _userPeerIndex.GetOrAdd(user.Id, peer.Id); if (r.Value != peer.Id) { await LogOut(r.Value); } else { added = true; } } await _userPeerIndex.TryAdd(onlineId.ToString(), peer.Id); await _peerUserIndex.TryAdd(peer.Id.ToString(), new Session { User = user, platformId = onlineId }); await _eventHandlers.RunEventHandler(h => h.OnLoggedIn(peer, user, onlineId), ex => logger.Log(LogLevel.Error, "usersessions", "An error occured while running LoggedIn event handlers", ex)); await _userService.LoginEventOccured(user, peer); //logger.Trace("usersessions", $"Added '{user.Id}' (peer : '{peer.Id}') in scene '{_scene.Id}'."); }
public static AuthenticationResult CreateFailure(string reason, PlatformId platformId, Dictionary <string, string> context) { return(new AuthenticationResult { Success = false, ReasonMsg = reason, PlatformId = platformId, AuthenticationContext = context }); }
public static AuthenticationResult CreateSuccess(User user, PlatformId platformId, Dictionary <string, string> context) { return(new AuthenticationResult { Success = true, AuthenticatedUser = user, PlatformId = platformId, AuthenticationContext = context }); }
public Task <Session> GetSession(PlatformId id) { return(GetSession(id.ToString())); }