diff --git a/book.json b/book.json index 6bbca32..5aadec2 100644 --- a/book.json +++ b/book.json @@ -22,6 +22,10 @@ { "lang": "rust", "name": "Rust" + }, + { + "lang": "cs", + "name": "C#" } ] } diff --git a/book/overview/oauth/authorization-code-grant.md b/book/overview/oauth/authorization-code-grant.md index 77c6242..7bd47e3 100644 --- a/book/overview/oauth/authorization-code-grant.md +++ b/book/overview/oauth/authorization-code-grant.md @@ -93,6 +93,49 @@ return json_decode($response->getBody())->access_token; This will return a JSON response containing the JWT `access_token`. {% endtab %} + +{% tab title="C#" %} +```cs +using Flurl; +using Flurl.Http; + +namespace YourApplication +{ + class AuthorizationResult + { + public string token_type { get; set; } + public int expires_in { get; set; } + public string access_token { get; set; } + public string refresh_token { get; set; } + } + + class Program + { + private static string Url = "https://anilist.co/api/v2/oauth/token"; + + public static async Task GetBearerToken() + { + var result = await Url + .PostJsonAsync(new + { + grant_type = "authorization_code", + client_id = "{client_id}", + client_secret = "{client_secret}", + redirect_uri = "{redirect_uri}", + code = "{code}" + }) + .ReceiveJson(); + + return result.access_token; + } + } +} + +``` + +This will return a JSON response containing the JWT `access_token`. +{% endtab %} + {% endtabs %} ## Making Authenticated Requests @@ -134,5 +177,26 @@ $response = $http->request('POST', 'https://graphql.anilist.co', [ ]); ``` {% endtab %} + +{% tab title="C#" %} +```cs +using Flurl; +using Flurl.Http; + +public static async Task GetQueryResult() +{ + var result = await "https://graphql.anilist.co" + .WithOAuthBearerToken({YOUR BEARER TOKEN HERE}) + .PostJsonAsync(new + { + query = "{YOUR QUERY STRING HERE}" + }) + .ReceiveString(); // For demo purposes, I will use ReceiveString method. But you should use ReceiveJson method to access the data + + return result; +} +``` +{% endtab %} + {% endtabs %} diff --git a/book/overview/oauth/implicit-grant.md b/book/overview/oauth/implicit-grant.md index e646f1b..dc6b0e6 100644 --- a/book/overview/oauth/implicit-grant.md +++ b/book/overview/oauth/implicit-grant.md @@ -80,5 +80,25 @@ $response = $http->request('POST', 'https://graphql.anilist.co', [ ]); ``` {% endtab %} + +{% tab title="C#" %} +```cs +using Flurl; +using Flurl.Http; + +public static async Task GetQueryResult() +{ + var result = await "https://graphql.anilist.co" + .WithOAuthBearerToken({YOUR BEARER TOKEN HERE}) + .PostJsonAsync(new + { + query = "{YOUR QUERY STRING HERE}" + }) + .ReceiveString(); // For demo purposes, I will use ReceiveString method. But you should use ReceiveJson method to access the data + + return result; +} +``` +{% endtab %} {% endtabs %}