Add Oauth2 Identity
curl --request POST \
--url https://codecombat.com/api/users/{handle}/o-auth-identities \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"provider": "<string>",
"accessToken": "<string>",
"code": "<string>"
}
'import requests
url = "https://codecombat.com/api/users/{handle}/o-auth-identities"
payload = {
"provider": "<string>",
"accessToken": "<string>",
"code": "<string>"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({provider: '<string>', accessToken: '<string>', code: '<string>'})
};
fetch('https://codecombat.com/api/users/{handle}/o-auth-identities', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://codecombat.com/api/users/{handle}/o-auth-identities",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'provider' => '<string>',
'accessToken' => '<string>',
'code' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://codecombat.com/api/users/{handle}/o-auth-identities"
payload := strings.NewReader("{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://codecombat.com/api/users/{handle}/o-auth-identities")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://codecombat.com/api/users/{handle}/o-auth-identities")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "<string>",
"email": "<string>",
"name": "<string>",
"slug": "<string>",
"role": "<string>",
"stats": {
"gamesCompleted": 123,
"concepts": {},
"playTime": 123
},
"oAuthIdentities": [
{
"provider": "<string>",
"id": "<string>"
}
],
"subscription": {
"ends": "<string>",
"active": true
},
"license": {
"ends": "<string>",
"active": true
}
}Users
Add Oauth2 Identity
Adds an OAuth2 identity to the user, so that they can be logged in with that identity. You need to send the OAuth code or the access token to this endpoint.
POST
/
users
/
{handle}
/
o-auth-identities
Add Oauth2 Identity
curl --request POST \
--url https://codecombat.com/api/users/{handle}/o-auth-identities \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"provider": "<string>",
"accessToken": "<string>",
"code": "<string>"
}
'import requests
url = "https://codecombat.com/api/users/{handle}/o-auth-identities"
payload = {
"provider": "<string>",
"accessToken": "<string>",
"code": "<string>"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({provider: '<string>', accessToken: '<string>', code: '<string>'})
};
fetch('https://codecombat.com/api/users/{handle}/o-auth-identities', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://codecombat.com/api/users/{handle}/o-auth-identities",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'provider' => '<string>',
'accessToken' => '<string>',
'code' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://codecombat.com/api/users/{handle}/o-auth-identities"
payload := strings.NewReader("{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://codecombat.com/api/users/{handle}/o-auth-identities")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://codecombat.com/api/users/{handle}/o-auth-identities")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"provider\": \"<string>\",\n \"accessToken\": \"<string>\",\n \"code\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "<string>",
"email": "<string>",
"name": "<string>",
"slug": "<string>",
"role": "<string>",
"stats": {
"gamesCompleted": 123,
"concepts": {},
"playTime": 123
},
"oAuthIdentities": [
{
"provider": "<string>",
"id": "<string>"
}
],
"subscription": {
"ends": "<string>",
"active": true
},
"license": {
"ends": "<string>",
"active": true
}
}- If no access token is provided, it will use your OAuth2 token URL to exchange the given code for an access token.
- Then it will use the access token (given by you, or received from step 1) to look up the user on your service using the lookup URL, and expects a JSON object in response with an id property.
- It will then save that user id to the user in our db as a new OAuthIdentity.
url = `https://codecombat.com/api/users/${userID}/o-auth-identities`;
OAUTH_PROVIDER_ID = "xyz";
json = { provider: OAUTH_PROVIDER_ID, accessToken: "1234" };
request.post({ url, json, auth }, (err, res) => {
console.log(res.body.oAuthIdentities); // [ { provider: 'xyx', id: 'abcd' } ]
});
https://oauth.provider/user?t=<%= accessToken %>) with the access token
(1234). The lookup URL returns { id: 'abcd' } in this case, which we save to
the user in our db.Authorizations
Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.
Path Parameters
The document's _id or slug.
Body
application/json
Response
200 - application/json
The affected user
Subset of properties listed here
Usually either 'teacher' or 'student'
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
