Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update authorization docs for C-sharp developers #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
64 changes: 64 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 Expand Up @@ -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<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 %}

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 %}