Get Access Tokens (2024)

To access your API, you must request an access token when authenticating a user.

These Auth0 tools help you modify your application to authenticate users:

To request an access token, make a POST call to the token URL.

Example POST to token URL

  • cURL
  • C#
  • Go
  • Java
  • Node.JS
  • Obj-C
  • ...
    • PHP
    • Python
    • Ruby
    • Swift
curl --request POST \ --url 'https://{yourDomain}/oauth/token' \ --header 'content-type: application/x-www-form-urlencoded' \ --data grant_type=client_credentials \ --data client_id=YOUR_CLIENT_ID \ --data client_secret=YOUR_CLIENT_SECRET \ --data audience=YOUR_API_IDENTIFIER

Was this helpful?

/

var client = new RestClient("https://{yourDomain}/oauth/token");var request = new RestRequest(Method.POST);request.AddHeader("content-type", "application/x-www-form-urlencoded");request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER", ParameterType.RequestBody);IRestResponse response = client.Execute(request);

Was this helpful?

/

package mainimport ("fmt""strings""net/http""io/ioutil")func main() {url := "https://{yourDomain}/oauth/token"payload := strings.NewReader("grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER")req, _ := http.NewRequest("POST", url, payload)req.Header.Add("content-type", "application/x-www-form-urlencoded")res, _ := http.DefaultClient.Do(req)defer res.Body.Close()body, _ := ioutil.ReadAll(res.Body)fmt.Println(res)fmt.Println(string(body))}

Was this helpful?

/

HttpResponse<String> response = Unirest.post("https://{yourDomain}/oauth/token") .header("content-type", "application/x-www-form-urlencoded") .body("grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER") .asString();

Was this helpful?

/

var axios = require("axios").default;var options = { method: 'POST', url: 'https://{yourDomain}/oauth/token', headers: {'content-type': 'application/x-www-form-urlencoded'}, data: new URLSearchParams({ grant_type: 'client_credentials', client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET', audience: 'YOUR_API_IDENTIFIER' })};axios.request(options).then(function (response) { console.log(response.data);}).catch(function (error) { console.error(error);});

Was this helpful?

/

#import <Foundation/Foundation.h>NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" };NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"grant_type=client_credentials" dataUsingEncoding:NSUTF8StringEncoding]];[postData appendData:[@"&client_id=YOUR_CLIENT_ID" dataUsingEncoding:NSUTF8StringEncoding]];[postData appendData:[@"&client_secret=YOUR_CLIENT_SECRET" dataUsingEncoding:NSUTF8StringEncoding]];[postData appendData:[@"&audience=YOUR_API_IDENTIFIER" dataUsingEncoding:NSUTF8StringEncoding]];NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/oauth/token"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];[request setHTTPMethod:@"POST"];[request setAllHTTPHeaderFields:headers];[request setHTTPBody:postData];NSURLSession *session = [NSURLSession sharedSession];NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"%@", error); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"%@", httpResponse); } }];[dataTask resume];

Was this helpful?

/

$curl = curl_init();curl_setopt_array($curl, [ CURLOPT_URL => "https://{yourDomain}/oauth/token", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER", CURLOPT_HTTPHEADER => [ "content-type: application/x-www-form-urlencoded" ],]);$response = curl_exec($curl);$err = curl_error($curl);curl_close($curl);if ($err) { echo "cURL Error #:" . $err;} else { echo $response;}

Was this helpful?

/

import http.clientconn = http.client.HTTPSConnection("")payload = "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER"headers = { 'content-type': "application/x-www-form-urlencoded" }conn.request("POST", "/{yourDomain}/oauth/token", payload, headers)res = conn.getresponse()data = res.read()print(data.decode("utf-8"))

Was this helpful?

/

require 'uri'require 'net/http'require 'openssl'url = URI("https://{yourDomain}/oauth/token")http = Net::HTTP.new(url.host, url.port)http.use_ssl = truehttp.verify_mode = OpenSSL::SSL::VERIFY_NONErequest = Net::HTTP::Post.new(url)request["content-type"] = 'application/x-www-form-urlencoded'request.body = "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER"response = http.request(request)puts response.read_body

Was this helpful?

/

import Foundationlet headers = ["content-type": "application/x-www-form-urlencoded"]let postData = NSMutableData(data: "grant_type=client_credentials".data(using: String.Encoding.utf8)!)postData.append("&client_id=YOUR_CLIENT_ID".data(using: String.Encoding.utf8)!)postData.append("&client_secret=YOUR_CLIENT_SECRET".data(using: String.Encoding.utf8)!)postData.append("&audience=YOUR_API_IDENTIFIER".data(using: String.Encoding.utf8)!)let request = NSMutableURLRequest(url: NSURL(string: "https://{yourDomain}/oauth/token")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)request.httpMethod = "POST"request.allHTTPHeaderFields = headersrequest.httpBody = postData as Datalet session = URLSession.sharedlet dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) }})dataTask.resume()

Was this helpful?

/

Parameters
Parameter NameDescription
grant_typeSet this to "client_credentials".
client_idYour application's Client ID. You can find this value on the application's settings tab.
client_secretYour application's Client Secret. You can find this value on the application's settings tab. To learn more about available application authentication methods, read Application Credentials.
audienceThe audience for the token, which is your API. You can find this in the Identifier field on your API's settings tab.

Response

You receive an HTTP 200 response with a payload containing access_token, token_type, and expires_in values:

{ "access_token":"eyJz93a...k4laUWw", "token_type":"Bearer", "expires_in":86400}

Was this helpful?

/

Validate your tokens before saving them. To learn how, read Validate ID Tokens and Validate Access Tokens.

Control access token audience

When a user authenticates, you request an access token and include the target audience and scope of access in your request. The application uses the /authorize endpoint to request access. This access is both requested by the application and granted by the user during authentication

You can configure your tenant to always include a default audience.

Token UseFormatRequested AudienceRequested Scope
/userinfo endpointOpaquetenant name ({yourDomain}), no value for audience parameter, no audience parameter passedopenid
Auth0 Management APIJWTManagement API v2 identifier (https://{tenant}.auth0.com/api/v2/)
Your own custom APIJWTThe API Identifier for your custom API registered in the Auth0 Dashboard

In only one specific instance, access tokens can have multiple target audiences. This requires that your custom API's signing algorithm is set to RS256. To learn more, read Token Best Practices.

Multiple audiences

If you specify an audience of your custom API identifier and a scope of openid, then the resulting access token's aud claim will be an array rather than a string, and the access token will be valid for both your custom API and for the /userinfo endpoint. Your access tokens can only have two or more audiences if you use a single custom API as well as Auth0's /userinfo endpoint.

Custom domains and the Auth0 Management API

Auth0 issues tokens with an issuer (iss) claim of whichever domain you used when requesting the token. Custom domain users can use either their custom domain or their Auth0 domain.

For example, suppose you have a custom domain, https://login.northwind.com. If you request an access token from https://login.northwind.com/authorize, your token's iss claim will be https://login.northwind.com/. However, if you request an access token from https://northwind.auth0.com/authorize, your token's iss claim will be https://northwind.auth0.com/.

If you request an access token from your custom domain with the target audience of the Auth0 Management API, then you must call the Auth0 Management API from your custom domain. Otherwise your access token is considered invalid.

Renew access tokens

By default, an access token for a custom API is valid for 86400 seconds (24 hours). You can shorten the time period before the token expires.

After an access token has expired, you can renew your access token. To do so either re-authenticate the user using Auth0 or use a refresh token.

Learn more

Get Access Tokens (2024)

FAQs

How do I pass an access token? ›

Access tokens are used in token-based authentication to allow an application to access an API. The application receives an access token after a user successfully authenticates and authorizes access, then passes the access token as a credential when it calls the target API.

How do I get my full access token for Facebook? ›

Obtain User Access Token
  1. Go to Graph API Explorer.
  2. In Facebook App, select an app used to obtain the access token.
  3. In User or Page, select User Token.
  4. Under Permissions, check ads_read .
  5. Click Generate Access Token. The box on top of the button is populated with the access token.
  6. Store that token for later use.

How do I get an access token in phrase? ›

To generate an access token, follow these steps: From the user menu (top right), hover over Settings and click on Profile. The Profile Settings page opens. Select the Access tokens tab and click Generate token.

How do I pass the access token in Postman? ›

To request an access token, fill out the fields in the Configure New Token section, and select Get New Access Token. To use the token with your request or collection, select Proceed and then select Use token. The details you used to generate the token are saved with your request or collection.

How do I get my access token? ›

Get Access Tokens
  1. To request an access token , make a POST call to the token URL.
  2. When a user authenticates, you request an access token and include the target audience and scope of access in your request. ...
  3. In only one specific instance, access tokens can have multiple target audiences.

How do I get Personal access tokens? ›

In the left sidebar, click Developer settings. In the left sidebar, under Personal access tokens, click Tokens (classic). Select Generate new token, then click Generate new token (classic). In the "Note" field, give your token a descriptive name.

What is an example of an access token? ›

Access tokens are used in token-based authentication to allow an application to access an API. For example, a Calendar application needs access to a Calendar API in the cloud so that it can read the user's scheduled events and create new events.

How do I get Facebook feed without access token? ›

No, you don't need an Access Token in order to use the Custom Facebook Feed plugin. An Access Token is required by Facebook in order to access their public data API. The plugin has a shared token built into it and so it isn't necessary for you to have your own to use the plugin.

How long do Facebook access tokens last? ›

If no requests are made, the token will expire after about 60 days and the person will have to go through the login flow again to get a new token.

What is an example of a token? ›

In general, a token is an object that represents something else, such as another object (either physical or virtual), or an abstract concept as, for example, a gift is sometimes referred to as a token of the giver's esteem for the recipient.

How do I create a secret access token? ›

To generate an access token, you will need a client secret. If you do not have a client secret yet, check the guide on creating an API client here. If you already have a client secret, use the "Generate Access Token API" as documented below.

How do I get my own token? ›

How to Create Your Own Crypto Token in 10 Easy Steps
  1. Define the purpose of your token. ...
  2. Choose a blockchain platform for your token. ...
  3. Select a token standard for your token. ...
  4. Design the token's name, symbol, supply, and distribution. ...
  5. Write the token's smart contract code. ...
  6. Test and deploy the token's smart contract.
Feb 26, 2024

How to generate Bearer Token? ›

How to Generate a Bearer Token on GitHub?
  1. Step 1: Register your application on GitHub. Go to your GitHub account settings. ...
  2. Step 2: Request authorization from the user. If you are registering a new application and got OAuth applications. ...
  3. Step 3: Exchange authorization code for a token. ...
  4. Step 4: Use the Bearer token.

How to get LinkedIn token? ›

Your application directs the browser to LinkedIn's OAuth 2.0 authorization page where the member authenticates. After authentication, LinkedIn's authorization server passes an authorization code to your application. Your application sends this code to LinkedIn and LinkedIn returns an access token.

What are the different types of authorization? ›

Types of authorization include discretionary access control (DAC), mandatory access control (MAC), role-based access control (RBAC), and attribute-based access control (ABAC). In this article, we'll cover the differences and the techniques that are being used to implement them.

How does token passing work? ›

On a local area network, token passing is a channel access method where a packet called a token is passed between nodes to authorize that node to communicate. In contrast to polling access methods, there is no pre-defined "master" node.

How to send access token to server? ›

Sending an access token in a request

To do this, the app sends the access token in the request as an "Authorization" HTTP header. Apigee Edge will verify that the access token presented is valid, and then grant access to the API, returning the response to the app that made the request.

How can I get access token authorization code? ›

The following section describes the steps for obtaining the access token and refresh token using the authorization code grant mechanism:
  1. Step 1: Authenticate a User and Create a User Session.
  2. Step 2: [Optional] Generating Client Credentials.
  3. Step 3: Generate Authorization Code.
  4. Step 4: Exchange Auth Code for a Token.

How do I push a code using personal access token? ›

Steps to Authenticate Git Push
  1. Step 1: Generate a Personal Access Token. Log in to GitHub: ...
  2. Step 2: Configure Git to Use Your Token. To authenticate Git operations with your token, you need to update the URL of your repository to include the token. ...
  3. Step 3: Test Your Configuration. Push to Repository:
May 31, 2024

Top Articles
Opportunities and Challenges of New Technologies for AML/CFT
Warren Buffett Forex Trading Strategy Explained to Beginners - MTrading
How To Fix Epson Printer Error Code 0x9e
Elleypoint
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Pinellas County Jail Mugshots 2023
What to Serve with Lasagna (80+ side dishes and wine pairings)
Jennette Mccurdy And Joe Tmz Photos
Mcoc Immunity Chart July 2022
Corpse Bride Soap2Day
Waive Upgrade Fee
Youtube Combe
What Is Njvpdi
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Moonshiner Tyler Wood Net Worth
Craigslist Edmond Oklahoma
Dumb Money, la recensione: Paul Dano e quel film biografico sul caso GameStop
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Fraction Button On Ti-84 Plus Ce
Earl David Worden Military Service
The Tower and Major Arcana Tarot Combinations: What They Mean - Eclectic Witchcraft
Best Boston Pizza Places
Deshuesadero El Pulpo
Mineral Wells Skyward
The Fabelmans Showtimes Near Baton Rouge
Myaci Benefits Albertsons
Vlacs Maestro Login
Craigslist Sf Garage Sales
Abga Gestation Calculator
404-459-1280
Marine Forecast Sandy Hook To Manasquan Inlet
Mistress Elizabeth Nyc
Troy Gamefarm Prices
The Banshees Of Inisherin Showtimes Near Reading Cinemas Town Square
Uvalde Topic
The Angel Next Door Spoils Me Rotten Gogoanime
Bekah Birdsall Measurements
Quaally.shop
Rocket Lab hiring Integration &amp; Test Engineer I/II in Long Beach, CA | LinkedIn
Unblocked Games - Gun Mayhem
A Man Called Otto Showtimes Near Cinemark Greeley Mall
Walmart Front Door Wreaths
Turok: Dinosaur Hunter
Minute Clinic Mooresville Nc
Cars & Trucks near Old Forge, PA - craigslist
Fredatmcd.read.inkling.com
2487872771
Spongebob Meme Pic
North Park Produce Poway Weekly Ad
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5528

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.