OAuth2 token exchange.
POST
application/x-www-form-urlencoded- body
client_id?stringClient ID, required if grant_type=authorization_code
client_secret?stringClient secret, required if grant_type=authorization_code and the client is confidential. Public clients (token_endpoint_auth_method=none) send no secret.
code?stringAuthorization code, required if grant_type=authorization_code
code_verifier?stringPKCE code verifier, required if grant_type=authorization_code. 43-128 characters per RFC 7636.
refresh_token?stringRefresh token, required if grant_type=refresh_token
grant_type*stringGrant type
Value in
"authorization_code""refresh_token""password""client_credentials""implicit"OK
application/json- response
access_token?stringexpires_in?integerexpiry?stringExpiry is not part of RFC 6749 but is included for compatibility with golang.org/x/oauth2.Token and clients that expect a timestamp.
Format
date-timerefresh_token?stringscope?stringtoken_type?codersdk.OAuth2TokenTypeValue in
"Bearer""DPoP"The samples read CODER_URL and CODER_SESSION_TOKEN: set up your environment.
curl -X POST \ "$CODER_URL/oauth2/tokens" \ -H "Content-Type: application/x-www-form-urlencoded" \ --data-binary "@{file}"import { readFile } from "node:fs/promises";const { CODER_URL } = process.env;const url = `${CODER_URL}/oauth2/tokens`;const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: await readFile("{file}"),});console.log(response.status, await response.text());import osimport requestsurl = os.environ["CODER_URL"] + "/oauth2/tokens"response = requests.post( url, headers={ "Content-Type": "application/x-www-form-urlencoded", }, data=open("{file}", "rb"),)print(response.status_code, response.text)package mainimport ( "fmt" "io" "net/http" "os")func main() { body, err := os.Open("{file}") if err != nil { panic(err) } defer body.Close() url := os.Getenv("CODER_URL") + "/oauth2/tokens" req, err := http.NewRequest(http.MethodPost, url, body) if err != nil { panic(err) } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(resp.Status, string(out))}Example Response
{ "access_token": "string", "expires_in": 0, "expiry": "2019-08-24T14:15:22Z", "refresh_token": "string", "scope": "string", "token_type": "Bearer"}