public async Task ShouldOAuthRequest() { await FHClient.Init(); //given ServiceFinder.RegisterType <IOAuthClientHandlerService, MockOAuthClient>(); var json = JObject.Parse(@"{ ""hosts"": {""host"": ""HOST""} }"); var config = new FHConfig(new MockDeviceService()); var props = new CloudProps(json, config); var authRequest = new FHAuthRequest(props); authRequest.SetAuthUser("gmail", "user", "password"); var mockHttpCLient = new MockHttpClient { Content = "{\"status\": \"ok\", \"url\": \"http://oauthurl.url\"}" }; FHHttpClientFactory.Get = () => mockHttpCLient; //when var response = await authRequest.ExecAsync(); //then Assert.IsNotNull(response); var responseParams = response.GetResponseAsDictionary(); Assert.IsNotNull(responseParams); Assert.AreEqual("token", responseParams["sessionToken"]); }
/// <summary> /// Call the FeedHenry Authentication API with the given policyId, user name and password. This is normally used for /// LDAP and other basic authentication types. /// </summary> /// <param name="policyId">The id of the auth policy</param> /// <param name="userName">The name of the user</param> /// <param name="userPassword">The user's password</param> /// <returns>The result of the authencation</returns> public static async Task <FHResponse> Auth(string policyId, string userName, string userPassword) { RequireAppReady(); var authRequest = new FHAuthRequest(CloudProps) { TimeOut = TimeOut }; authRequest.SetAuthUser(policyId, userName, userPassword); return(await authRequest.ExecAsync()); }