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"]);
        }
Example #2
0
 /// <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();
     FHAuthRequest authRequest = new FHAuthRequest(cloudProps);
     authRequest.TimeOut = timeout;
     authRequest.SetAuthUser(policyId, userName, userPassword);
     return await authRequest.execAsync();
 }
Example #3
0
 /// <summary>
 ///     Call the FeedHenry Authentication API with the given policyId. This is normally used for OAuth type
 ///     authentications.
 ///     The user will be prompted for login details and the the login result will be returned.
 /// </summary>
 /// <param name="policyId">The id of the new policy</param>
 /// <returns>The result of the authencation</returns>
 public static async Task<FHResponse> Auth(string policyId)
 {
     RequireAppReady();
     var authRequest = new FHAuthRequest(CloudProps) {TimeOut = TimeOut};
     authRequest.SetAuthPolicyId(policyId);
     return await authRequest.ExecAsync();
 }