public async void ClientCredentialsGrant() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.gfycat.com/v1/oauth/token") .WithJsonContent( new { grant_type = "client_credentials", client_id, client_secret, }) .Respond( new { token_type = "bearer", scope = "", expires_in = 3600, access_token }); var config = new GfycatClientConfig(client_id, client_secret) { RestClient = new MockMessageClient(mockHttp) }; var client = new GfycatClient(config); await client.AuthenticateAsync(); Assert.Equal(access_token, client.AccessToken); }
public async void ClientAuthAsync() { await Client.AuthenticateAsync(); Assert.Equal(Resources.AccessToken, Client.AccessToken); }
public async void PasswordGrant() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.gfycat.com/v1/oauth/token") .WithJsonContent( new { grant_type = "password", client_id, client_secret, username, password }) .Respond( new { token_type = "bearer", refresh_token_expires_in = 5184000, refresh_token, scope = "", resource_owner = username, expires_in = 3600, access_token }); mockHttp.When(HttpMethod.Get, "https://api.gfycat.com/v1/me") .WithHeaders("Authorization: Bearer " + access_token) .Respond( new { userid = "", username, email = "*****@*****.**", description = "description", profileUrl = "https://github.com/username", name = "username", views = 9001, uploadNotices = true, emailVerified = true, url = "https://gfycat.com/@username", createDate = 0, profileImageUrl = "http://cdn.edgecast.steamstatic.com/steamcommunity/public/images/avatars/c9/c9c3bbe7ffb21f9b0ae54c1d48c8a42257b7b621_full.jpg", verified = true, followers = 0, following = 1, geoWhitelist = new[] { "us" }, domainWhitelist = new[] { "reddit.com" }, associatedProviders = new[] { "facebook" }, iframeProfileImageVisible = true }); var config = new GfycatClientConfig(client_id, client_secret) { RestClient = new MockMessageClient(mockHttp) }; var client = new GfycatClient(config); await client.AuthenticateAsync(username, password); Assert.Equal(access_token, client.AccessToken); Assert.Equal(refresh_token, client.RefreshToken); Assert.Equal(username, client.CurrentUser.Username); }