public async Task UsesCallbackToRetrievTwoFactorCode() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var secondResponse = new Authorization {Token = "OAUTHSECRET"}; var client = Substitute.For<IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw<Authorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?"}, _ => Observable.Return(twoFactorChallengeResult)); Assert.Equal("OAUTHSECRET", result.Token); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is<NewAuthorization>(a => a.Note == "Was it this one?")); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is<NewAuthorization>(a => a.Note == "Was it this one?"), "two-factor-code"); }
public async Task UsesCallbackToRetrieveTwoFactorCode() { var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var data = new NewAuthorization { Note = "note" }; var client = Substitute.For <IAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any <NewAuthorization>()) .Returns <Task <ApplicationAuthorization> >(_ => { throw new TwoFactorRequiredException(); }); client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any <NewAuthorization>(), "two-factor-code") .Returns(Task.Factory.StartNew(() => new ApplicationAuthorization("xyz"))); var result = await client.GetOrCreateApplicationAuthentication("clientId", "secret", data, e => Task.Factory.StartNew(() => twoFactorChallengeResult)); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Is <NewAuthorization>(u => u.Note == "note")); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any <NewAuthorization>(), "two-factor-code"); Assert.Equal("xyz", result.Token); }
public async Task UsesCallbackToRetrievTwoFactorCode() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var secondResponse = new ApplicationAuthorization("OAUTHSECRET"); var client = Substitute.For <IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw <ApplicationAuthorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?" }, _ => Observable.Return(twoFactorChallengeResult)); Assert.Equal("OAUTHSECRET", result.Token); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is <NewAuthorization>(a => a.Note == "Was it this one?")); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is <NewAuthorization>(a => a.Note == "Was it this one?"), "two-factor-code"); }
public async Task UsesCallbackToRetrieveTwoFactorCode() { var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var data = new NewAuthorization { Note = "note" }; var client = Substitute.For<IAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any<NewAuthorization>()) .Returns<Task<ApplicationAuthorization>>(_ => { throw new TwoFactorRequiredException(); }); client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any<NewAuthorization>(), "two-factor-code") .Returns(Task.Factory.StartNew(() => new ApplicationAuthorization("xyz"))); var result = await client.GetOrCreateApplicationAuthentication("clientId", "secret", data, e => Task.Factory.StartNew(() => twoFactorChallengeResult)); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Is<NewAuthorization>(u => u.Note == "note")); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any<NewAuthorization>(), "two-factor-code"); Assert.Equal("xyz", result.Token); }