From 1542bd5e0533c535a5b4410ff83f1db8956a5acd Mon Sep 17 00:00:00 2001 From: Brian Corrigan Date: Wed, 4 Oct 2017 08:48:13 -0400 Subject: Initial commit --- en/authorization.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 en/authorization.md (limited to 'en/authorization.md') diff --git a/en/authorization.md b/en/authorization.md new file mode 100644 index 0000000..1838477 --- /dev/null +++ b/en/authorization.md @@ -0,0 +1,98 @@ +{% method %} +# Authorization + +We require a JSON Web Token ([JWT](https://jwt.io/)) be sent along with your request via the `Authorization` header. +JWTs are passed as bearer tokens in the Authorization header, and look like the following: + +`Authorization: ` + + +There's no need to create JWTs manually, they will be created for you when you register for the API - [Register Here!](https://developer.vainglorygame.com/users/sign_in) + +In some cases an `X-API-KEY` will give you more access to information, and in all cases it means that you are operating under a per-token rate limit. + +{% sample lang="shell" %} +> To specify the Headers, use this code: + +```shell + # With shell, you can just pass the correct header with each request + curl "" \ + -H "Authorization: " + -H "Accept: application/vnd.api+json" +``` +{% sample lang="java" %} +```java +import java.io.*; +import java.net.*; + +URL url = new URL(""); +HttpURLConnection conn = (HttpURLConnection) url.openConnection(); +conn.setRequestMethod("GET"); +conn.setRequestProperty("Authorization",""); +conn.setRequestProperty("Accept", "application/vnd.api+json"); + +conn.getInputStream() +``` + +{% sample lang="python" %} +```python +import requests + +url = "" + +header = { + "Authorization": "", + "Accept": "application/vnd.api+json" +} + +r = requests.get(url, headers=header) +``` +{% sample lang="ruby" %} +```ruby +``` +{% sample lang="js" %} +```javascript +``` + +{% sample lang="go" %} +```go +import "net/http" + +client := &http.Client{} +req, _ := http.NewRequest("GET","",nil) +req.Header.Set("Authorization", "") +req.Header.Set("Accept", "application/vnd.api+json") +res, _ := client.Do(req) +``` + +{% sample lang="swift" %} +```swift +import Foundation + +let urlString = endpoint-url" + +let url = NSURL(string: urlString) +var downloadTask = URLRequest(url: (url as URL?)!, cachePolicy: URLRequest.CachePolicy.ReloadIgnoringCacheData, timeoutInterval: 20) + +downloadTask.httpMethod = "GET" + +downloadTask.addValue("apiKey", forHTTPHeaderField: "Authorization") +downloadTask.addValue("application/vnd.api+json", forHTTPHeaderField: "Accept") + +URLSession.shared.dataTask(with: downloadTask) { (data, response, error) in +if let response = response { + print(response) +} + +if let data = data { + do { + let jsonData = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? NSDictionary + print(jsonData!.value(forKey: "data") as Any) + } catch { + print(error) + } +} +}.resume() +``` + +{% endmethod %} -- cgit v1.3.1