/// <summary> /// Sets the <see cref="IAuthableSession"/>s <see cref="IAuthToken"/> field <see cref="Token"/> /// if the token is valid. /// </summary> /// <param name="ticket">A valid authentication token.</param> /// <exception cref="ArgumentNullException">If the token is null.</exception> /// <exception cref="InvalidOperationException">If the token is in an invalid state.</exception> public void SetAuthenticationTicket(AuthTicketContainer ticket) { #if DEBUG || DEBUGBUILD Debug.Log($"Successfully used oAuth token to authenticate on game servers."); #endif Throw <ArgumentNullException> .If.IsNull(ticket)?.Now(nameof(ticket), $"Recieved a null {nameof(AuthTicket)} during auth token set."); AuthenticationTicketContainer = ticket; //There was no reason to reauth if (CurrentSessionState.HasFlag(SessionState.HasValidAuthTicket)) { return; } CurrentSessionState = CurrentSessionState | SessionState.HasValidAuthTicket; //Call the event handler if it's not null StatusChangedEvent?.Invoke(CurrentSessionState); }
/// <summary> /// Sets the <see cref="IAuthableSession"/>s <see cref="IAuthToken"/> field <see cref="Token"/> /// if the token is valid. /// </summary> /// <param name="token">A valid authentication token.</param> /// <exception cref="ArgumentNullException">If the token is null.</exception> /// <exception cref="InvalidOperationException">If the token is in an invalid state.</exception> public void SetAuthenticationToken(IAuthToken token) { #if DEBUG || DEBUGBUILD Debug.Log($"Successfully authenticated and recieved valid oAuth."); #endif Throw <ArgumentNullException> .If.IsNull(token)?.Now(nameof(token), $"Recieved a null {nameof(IAuthToken)} during auth token set."); if (!token.isValid) { Throw <InvalidOperationException> .If.Now(); //TODO: Add Easyception exception message } Token = token; //There was no reason to reauth if (CurrentSessionState.HasFlag(SessionState.Authenticated)) { return; } CurrentSessionState = CurrentSessionState | SessionState.Authenticated; //Call the event handler if it's not null StatusChangedEvent?.Invoke(CurrentSessionState); }