public void Handle_response(string id_, string jwtResponse, string expectedStatus, bool isNewAccount, string expectedState) { IAccountResult accountResultFromListener = null; var listener = new InlineIdSiteSyncResultListener( onAuthenticated: result => { if (expectedStatus == IdSiteResultStatus.Authenticated) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }, onLogout: result => { if (expectedStatus == IdSiteResultStatus.Logout) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }, onRegistered: result => { if (expectedStatus == IdSiteResultStatus.Registered) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }); var testApiKey = ClientApiKeys.Builder().SetId("2EV70AHRTYF0JOA7OEFO3SM29").SetSecret("goPUHQMkS4dlKwl5wtbNd91I+UrRehCsEDJrIrMruK8").Build(); var fakeRequestExecutor = Substitute.For <IRequestExecutor>(); fakeRequestExecutor.ApiKey.Returns(testApiKey); this.dataStore = TestDataStore.Create(fakeRequestExecutor, Caches.NewInMemoryCacheProvider().Build()); var request = new DefaultHttpRequest(HttpMethod.Get, new CanonicalUri($"https://foo.bar?{IdSiteClaims.JwtResponse}={jwtResponse}")); IIdSiteSyncCallbackHandler callbackHandler = new DefaultIdSiteSyncCallbackHandler(this.dataStore, request); callbackHandler.SetResultListener(listener); var accountResult = callbackHandler.GetAccountResult(); // Validate result (accountResult as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs"); (accountResultFromListener as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs"); accountResult.IsNewAccount.ShouldBe(isNewAccount); accountResultFromListener.IsNewAccount.ShouldBe(isNewAccount); accountResult.State.ShouldBe(expectedState); accountResultFromListener.State.ShouldBe(expectedState); var expectedResultStatus = IdSiteResultStatus.Parse(expectedStatus); accountResult.Status.ShouldBe(expectedResultStatus); accountResultFromListener.Status.ShouldBe(expectedResultStatus); }
internal static IdSiteResultStatus GetResultStatus(IJwtClaims claims) => IdSiteResultStatus.Parse((string)claims.GetClaim(IdSiteClaims.Status));