protected override void OnLaunched(LaunchActivatedEventArgs e) { // smooth merchant thumbnail image resizing new BitmapTransform().InterpolationMode = BitmapInterpolationMode.Cubic; Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { var navigationService = new NavigationService(rootFrame); var loginPageViewModel = new LoginPageViewModel(); var accountPageViewModel = new AccountPageViewModel(); var schedulerService = new SchedulerService(); var mondoAuthorizationClient = new MondoAuthorizationClient("YOUR_CLIENT_ID_HERE", "YOUR_CLIENT_SECRET_HERE", "https://production-api.gmon.io"); var appController = new AppController(navigationService, mondoAuthorizationClient, loginPageViewModel, accountPageViewModel, schedulerService); appController.Start(); rootFrame.Navigate(typeof(LoginPage), e.Arguments); rootFrame.DataContext = loginPageViewModel; } Window.Current.Activate(); }
public void GetLoginPageUrl() { using (var client = new MondoAuthorizationClient("testClientId", "testClientSecret", "http://foo")) { var loginPageUrl = client.GetAuthorizeUrl("testState", "testRedirectUri"); Assert.AreEqual("https://auth.getmondo.co.uk/?response_type=code&client_id=testClientId&state=testState&redirect_uri=testRedirectUri", loginPageUrl); } }
public async void Authenticate() { using (var server = TestServer.Create(app => { app.Run(async context => { Assert.AreEqual("/oauth2/token", context.Request.Uri.PathAndQuery); var formCollection = await context.Request.ReadFormAsync(); Assert.AreEqual("password", formCollection["grant_type"]); Assert.AreEqual("testClientId", formCollection["client_id"]); Assert.AreEqual("testClientSecret", formCollection["client_secret"]); Assert.AreEqual("testUsername", formCollection["username"]); Assert.AreEqual("testPassword", formCollection["password"]); await context.Response.WriteAsync( @"{ 'access_token': 'testAccessToken', 'client_id': 'client_id', 'expires_in': 21600, 'refresh_token': 'testRefreshToken', 'token_type': 'Bearer', 'user_id': 'testUserId' }" ); }); })) { using (var client = new MondoAuthorizationClient(server.HttpClient, "testClientId", "testClientSecret")) { var accessToken = await client.AuthenticateAsync("testUsername", "testPassword"); Assert.AreEqual("testAccessToken", accessToken.Value); Assert.AreEqual("testRefreshToken", accessToken.RefreshToken); Assert.AreEqual("testUserId", accessToken.UserId); Assert.AreEqual(21600, accessToken.ExpiresIn); } } }
public async void ExchangeCodeForAccessTokenAsync() { using (var server = TestServer.Create(app => { app.Run(async context => { Assert.AreEqual("/oauth2/token", context.Request.Uri.PathAndQuery); var formCollection = await context.Request.ReadFormAsync(); Assert.AreEqual("authorization_code", formCollection["grant_type"]); Assert.AreEqual("testClientId", formCollection["client_id"]); Assert.AreEqual("testClientSecret", formCollection["client_secret"]); Assert.AreEqual("testRedirectUri", formCollection["redirect_uri"]); Assert.AreEqual("testCode", formCollection["code"]); await context.Response.WriteAsync( @"{ 'access_token': 'testAccessToken', 'client_id': 'client_id', 'expires_in': 21600, 'refresh_token': 'testRefreshToken', 'token_type': 'Bearer', 'user_id': 'testUserId' }" ); }); })) { using (var client = new MondoAuthorizationClient(server.HttpClient, "testClientId", "testClientSecret")) { var accessToken = await client.GetAccessTokenAsync("testCode", "testRedirectUri"); Assert.AreEqual("testAccessToken", accessToken.Value); Assert.AreEqual("testRefreshToken", accessToken.RefreshToken); Assert.AreEqual("testUserId", accessToken.UserId); Assert.AreEqual(21600, accessToken.ExpiresIn); } } }