This project is a consumption example of Riot Games Developer API (RGAPI).
All endpoints requires authentication and there are two ways of authentication:
Anyone who signs into the developer portal will automatically be granted an API key that will be associated with their account. Your API key allows you to start using the API immediately, and allows us to generate API usage metrics for your key. See example.
For more information about API Keys read the full docs.
Some endpoints requires authorization from the user, and for this purpose RGAPI uses oauth2 protocol. See example.
To setup this project locally a few steps are needed, they are:
- Configure environment variables
- Add rule for localhost domain (only for oauth2 authentication)
- Boot Golang server
You can get the API Key after sign in at Riot Games Developer Portal. This token will be used as environment variable RIOT_API_TOKEN
.
For oauth2 authentication are needed two credentials, they are CLIENT_ID
and CLIENT_SECRET
and will be used respectively for environment variables RSO_CLIENT_ID
and RSO_CLIENT_SECRET
.
Contact us if you'd like to request access for oauth2.
Copy file .env.example
to a new file named .env
.
cp .env.example .env
copy .env.example .env
Set the environment variables with the credentials created in the last steps. For example:
APP_PORT=3000
RSO_CLIENT_ID=<YOUR-CLIENT-ID>
RSO_CLIENT_SECRET=<YOUR-CLIENT-SECRET>
RIOT_API_TOKEN=<YOUR-RIOT-API-TOKEN>
If you are not going to test oauth2 authentication, leave RSO_CLIENT_ID
and RSO_CLIENT_SECRET
empty.
To use oauth2 authentication redirect flows is needed to match your app hostname with the redirect_uri
provided when getting credentials for oauth2.
If you are not going to test oauth2 authentication, go to step Golang.
Open hosts file C:\Windows\System32\Drivers\etc\hosts
Add your hostname to localhost ip
127.0.0.1 local.exampleapp.com
Open hosts file /etc/hosts
Add your hostname to localhost ip
127.0.0.1 local.exampleapp.com
Linux users will need to edit hosts file as superuser (sudo)
You must have golang 1.18
version or higher. To check golang version
go version
Download module dependencies
go mod download
Simply run the following command to start your Golang server
go run main.go
For this example we have a use case of retrieving a summoner's league entries. The expected inputs are summoner's name and region.
The data we want can be retrieved at endpoint /lol/league/v4/entries/by-summoner/{encryptedSummonerId} that returns summoner's league entries and expects a summoner encrypted ID.
With our input we can consume endpoint /lol/summoner/v4/summoners/by-name/{summonerName} and obtain summoner's encrypted ID.
After booting server make a request GET localhost:3000/summoners/overview?region={summonerRegion}&name={summonerName}
Available regions are:
- BR1
- EUN1
- EUW1
- JP1
- KR
- LA1
- LA2
- NA1
- OC1
- RU
- TR1
curl -X GET "localhost:3000/summoners/overview?region={region}&name={summonerName}"
Navigate to localhost:3000/summoners/overview?region={region}&name={summonerName}
{
"id": "summonerID",
"name": "SummonerName",
"profileIconId": 1,
"summonerLevel": 10,
"revisionDate": "2022-01-17T18:14:50-03:00",
"leagueEntries": [
{
"leagueId": "leagueID",
"queueType": "RANKED_SOLO_5x5",
"tier": "CHALLENGER",
"rank": "I",
"leaguePoints": 1071,
"wins": 194,
"losses": 164,
"hotStreak": true,
"veteran": true,
"freshBlood": false,
"inactive": false
}
]
}
For this example we will authenticate through RSO (Riot SSO) and request account data by using oauth2 access token.
- Open the example app with the host you defined
- Follow the
Sign In
link
You will be redirected to Riot SSO Login Page. Authenticate using your account credentials.
After login you will be redirected to local app. Click My Account
. The app will request /riot/account/v1/accounts/me using an access token of your account.
When following My Account
you receive a response with the same structure of this example:
{
"puuid": "Player Universal Unique ID",
"gameName": "Game Name",
"tagLine": "Tag Line"
}
The json values are only examples. For puuid you will receive an encrypted string.
Go to app home (local.exampleapp.com:3000
) and click Logout
.
You will be redirect to riot SSO logout flow. If you return to the app home page you will see Sign In
link.