Example #1
0
    // Limitation note: so this GlobalSignOutAsync signs out the user from ALL devices, and not just the game.
    // So if you had other sessions for your website or app, those would also be killed.
    // Currently, I don't think there is native support for granular session invalidation without some work arounds.
    public async void SignOut()
    {
        await _user.GlobalSignOutAsync();

        // Important! Make sure to remove the local stored tokens
        UserSessionCache userSessionCache = new UserSessionCache("", "", "", "");

        SaveDataManager.SaveJsonData(userSessionCache);

        Debug.Log("user logged out.");
    }
Example #2
0
        private async void tappedEventHandler(object sender, TappedRoutedEventArgs e)
        {
            await userF.GlobalSignOutAsync();

            CoreApplicationView loginPage = CoreApplication.CreateNewView();
            int newViewId = 0;
            await loginPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                Frame frame = new Frame();
                frame.Navigate(typeof(MainPage));
                Window.Current.Content = frame;
                Window.Current.Activate();

                newViewId = ApplicationView.GetForCurrentView().Id;
            });

            await ApplicationViewSwitcher.SwitchAsync(newViewId, currentID, ApplicationViewSwitchingOptions.ConsolidateViews);
        }
Example #3
0
        public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response, FinanceUser user)
        {
            string idToken      = CookieReader.GetCookie(request, "idToken");
            string refreshToken = CookieReader.GetCookie(request, "refreshToken");

            if (string.IsNullOrWhiteSpace(idToken) || string.IsNullOrWhiteSpace(refreshToken))
            {
                response.StatusCode = 400;
                response.Body       = new JObject {
                    { "error", "idToken and refreshToken cookies are required" }
                }.ToString();
                return;
            }
            var provider    = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);
            var userPool    = new CognitoUserPool(Configuration.FINANCE_API_COGNITO_USER_POOL_ID, Configuration.FINANCE_API_COGNITO_CLIENT_ID, provider);
            var cognitoUser = new CognitoUser(user.Email, Configuration.FINANCE_API_COGNITO_CLIENT_ID, userPool, provider)
            {
                SessionTokens = new CognitoUserSession(null, null, refreshToken, DateTime.UtcNow, DateTime.UtcNow.AddHours(1))
            };
            InitiateRefreshTokenAuthRequest refreshRequest = new InitiateRefreshTokenAuthRequest
            {
                AuthFlowType = AuthFlowType.REFRESH_TOKEN_AUTH
            };
            var refreshResponse = cognitoUser.StartWithRefreshTokenAuthAsync(refreshRequest).Result;

            cognitoUser.SessionTokens = new CognitoUserSession(null, refreshResponse.AuthenticationResult.AccessToken, refreshToken, DateTime.Now, DateTime.Now.AddHours(1));
            cognitoUser.GlobalSignOutAsync().Wait();
            response.MultiValueHeaders = new Dictionary <string, IList <string> >
            {
                {
                    "Set-Cookie", new List <string>
                    {
                        "idToken=;Path=/;Secure;HttpOnly;expires=Thu, 01 Jan 1970 00:00:00 UTC",
                        "refreshToken=;Path=/;Secure;HttpOnly;expires=Thu, 01 Jan 1970 00:00:00 UTC"
                    }
                }
            };
            response.Body = Constants.JSON_EMPTY;
        }