Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
{
"lang": "rust",
"name": "Rust"
},
{
"lang": "cs",
"name": "C#"
}
]
}
Expand Down
43 changes: 43 additions & 0 deletions book/overview/oauth/authorization-code-grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<AuthorizationResult>();

return result.access_token;
}
}
}

```

This will return a JSON response containing the JWT `access_token`.
{% endtab %}

{% endtabs %}

## Making Authenticated Requests
Expand Down
20 changes: 20 additions & 0 deletions book/overview/oauth/implicit-grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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 %}