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
Expensive Purchases That Are Worth It — 10 Times To Choose Quality Over Quantity - Dividend Income Investor
Things to do in The Hague, Netherlands - beyond politics
Chs.mywork
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
4-Hour Private ATV Riding Experience in Adirondacks 2024 on Cool Destinations
Http://N14.Ultipro.com
Phone Number For Walmart Automotive Department
Chalupp's Pizza Taos Menu
Zitobox 5000 Free Coins 2023
Www Thechristhospital Billpay
Mivf Mdcalc
Ktbs Payroll Login
4Chan Louisville
Obituary | Shawn Alexander | Russell Funeral Home, Inc.
Yesteryear Autos Slang
Rosemary Beach, Panama City Beach, FL Real Estate & Homes for Sale | realtor.com®
Premier Reward Token Rs3
Salem Oregon Costco Gas Prices
Shopmonsterus Reviews
Shiftselect Carolinas
Maxpreps Field Hockey
A Person That Creates Movie Basis Figgerits
Papa Johns Mear Me
New Stores Coming To Canton Ohio 2022
Goodwill Of Central Iowa Outlet Des Moines Photos
Wku Lpn To Rn
Craigslist Fort Smith Ar Personals
The Collective - Upscale Downtown Milwaukee Hair Salon
Cfv Mychart
LG UN90 65" 4K Smart UHD TV - 65UN9000AUJ | LG CA
Housing Assistance Rental Assistance Program RAP
Forager How-to Get Archaeology Items - Dino Egg, Anchor, Fossil, Frozen Relic, Frozen Squid, Kapala, Lava Eel, and More!
Save on Games, Flamingo, Toys Games & Novelties
Nacho Libre Baptized Gif
Whitehall Preparatory And Fitness Academy Calendar
20+ Best Things To Do In Oceanside California
Frcp 47
Daly City Building Division
Citibank Branch Locations In Orlando Florida
888-822-3743
Pathfinder Wrath Of The Righteous Tiefling Traitor
Petra Gorski Obituary (2024)
Elven Steel Ore Sun Haven
CrossFit 101
The Sports Academy - 101 Glenwest Drive, Glen Carbon, Illinois 62034 - Guide
Dicks Mear Me
House For Sale On Trulia
La Fitness Oxford Valley Class Schedule
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.