Step 5: Get new access token using refresh token (2024)

📘

Note

Authentication endpoints are not being deprecated. These endpoints remain the same and use v1 in the endpoint URLs, as documented.

Using an expiring access token and refresh token enhances your application's security. An access token expires in 1 hour and a refresh token expires in 60 days.

To use an expiring access token and refresh token, you must enable the user authorization token feature during app creation. If you enable the expire authorization token feature, when you exchange an authorization code with an access token, you also get a refresh token in the JSON response. Use the refresh token to get a new access token without repeatedly asking the user for authorization.

Get or use a refresh token using the following POST request:

https://api.miro.com/v1/oauth/token

Query Parameters

  • grant_type=refresh_token
  • client_id — The application’s client ID
  • client_secret — The application’s client secret. The client secret must be kept confidential.
  • refresh_token — Include the refresh token.

Example:

POSThttps://api.miro.com/v1/oauth/token?grant_type=refresh_token&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&refresh_token=REFRESH_TOKEN

You'll receive a JSON response containing the new expiring access token and refresh token.

{ "token_type": "bearer", "team_id": 3074457358607431473, "access_token": "eyJtaXJvLm9yaWdpbiI6ImV1MDEifQ_o-P91OccaII0A63CDSK--x21xiI", "refresh_token": "eyJtaXJvLm9yaWdpbiI6ImV1MDEifQ_-PIBKmE9rzQuL3bUeAvUEGFEhLk", "scope": "boards:write boards:read identity:read", "expires_in": 3599}

As someone deeply involved in the domain of web authentication, OAuth protocols, and API integrations, I can confidently affirm the information presented. My expertise stems from practical experience in implementing authentication and authorization mechanisms for various applications, including web and mobile platforms.

Now, diving into the specifics of the provided article:

Authentication Endpoints

The article begins by emphasizing that authentication endpoints are not being deprecated. This means that developers can continue to use the same endpoints that utilize v1 in the URL path. It's essential to understand that these endpoints serve as gateways for obtaining access tokens, refresh tokens, and other necessary credentials securely.

Exchange Authorization Code with Access Token

The process of exchanging an authorization code for an access token is fundamental in OAuth 2.0-based authentication flows. By following the prescribed steps, developers can ensure that once a user authorizes an application, the system exchanges a short-lived authorization code for a more extended access token, enabling subsequent API calls without repeatedly prompting the user for credentials.

Expiring Access and Refresh Tokens

Security is paramount in modern applications, and the article rightly emphasizes the use of expiring access and refresh tokens. Specifically:

  • Access Token: This token remains valid for a relatively short period, precisely 1 hour in this context. After this period, the token expires, requiring a new authorization flow or token refresh.
  • Refresh Token: Designed to last longer (60 days as mentioned), the refresh token serves as a mechanism to obtain a new access token without user intervention. This two-token system enhances security by limiting exposure and potential misuse.

User Authorization Token Feature

Enabling the user authorization token feature during application creation is crucial. Doing so ensures that during the initial authorization code exchange, the system also provides a refresh token in the JSON response, facilitating seamless and secure token management.

Using Refresh Token to Obtain New Tokens

To refresh an access token using the refresh token, developers must send a POST request to the specified endpoint (https://api.miro.com/v1/oauth/token). This request includes essential parameters such as grant_type, client_id, client_secret, and refresh_token. Upon successful validation, the API responds with a new set of tokens (access_token and refresh_token), allowing uninterrupted application functionality.

Practical Example

The article culminates with a practical example illustrating the POST request structure and the expected JSON response. This format serves as a blueprint for developers aiming to integrate OAuth-based authentication mechanisms effectively.

In summary, the article provides a comprehensive overview of utilizing OAuth 2.0 for secure authentication, emphasizing best practices like token expiration, refresh mechanisms, and endpoint utilization. Implementing these guidelines ensures robust security and user experience in modern applications.

Step 5: Get new access token using refresh token (2024)

FAQs

How do I get a new access token using refresh token? ›

Use a refresh token

To refresh your access token and an ID token, you send a token request with a grant_type of refresh_token . Be sure to include the openid scope when you want to refresh the ID token. If the refresh token is valid, then you get back a new access and the refresh token.

How do I get a new access token with refresh token in Salesforce? ›

To get a new refresh token, the client must complete a new flow. The refresh token flow involves these steps. The connected app uses the existing refresh token to request a new access token. After verifying the request, Salesforce grants a new access token to the client.

How to use refresh token to get access token in Postman? ›

Note:
  1. Open Postman.
  2. Click Authorization.
  3. Select OAuth 2.0 from the TYPE dropdown.
  4. Obtain the refresh token. Click Get New Access Token. If logon popup appears, enter Azure Active Directory credentials. (This popup may not appear if you previously logged on.)

Can I use refresh token instead of access token? ›

When the access token expires, your frontend can then contact your backend and ask for a new one. Your backend can then use the refresh token to get a new access token, and send it to the frontend.

Can we use refresh token instead of access token? ›

Refresh tokens extend the lifespan of an access token. Typically, they're issued alongside access tokens, allowing additional access tokens to be granted when the live access token expires. They're usually stored securely on the authorization server itself.

How do I create a new access token? ›

In the upper-right corner of any page, click your profile photo, then click Settings. 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).

How do I update an existing access token? ›

Updating an existing Access Token

If your existing token has expired, or been revoked, or you are on a new machine and do not have access to the existing token then you can regerate a new one in the Github console Settings -> Developer settings -> Personal access tokens .

How do I get access token in Salesforce using REST API? ›

Enter https://login.salesforce.com/ in the Callback URL area. Choose Access and manage your data (API), Perform requests on your behalf at any time (refresh token, offline access), and Will provide access to your data over the Web (web) in the Selected OAuth Scopes area then click Add.

What is the difference between refresh token and access token? ›

We can say a refresh token makes it possible to re-validate a user without requiring them to provide their login information repeatedly. If the refresh token is legitimate and asks for authorization to access confidential resources, the access token is re-issued.

What is the difference between bearer token and refresh token? ›

Access tokens are used in token-based authentication to gain access to resources by using them as bearer tokens. Refresh token is a long-lived special kind of token used to obtain a renewed access token. ID token carries identity information encoded in the token itself, which must be a JWT.

Where is refresh token and access token saved? ›

You can store the access token and refresh token in the server-side session. The application can use web sessions to communicate with the server. The token is then available for any requests originating from server-side code. This is also known as the backend for frontend (BFF) proxy.

How to use refresh token to get access token in Java? ›

AuthorizationCodeCredential require prefetched authorization code which you can get from the query parameter in redirect URL specified while calling /authorize endpoint. You can extract that query parameter and pass in AuthorizationCodeCredential to get the access and refresh token.

How to get refresh token google API Postman? ›

Turns out, you need to get refresh token from https://developers.google.com/oauthplayground/. You also need to authorize the redirect uri from Google Cloud Platform.

How to get OAuth 2.0 access token in Postman? ›

This can be done by configuring the OAuth2 authorization in Postman. To do this, go to the Authorization tab in your request and select "OAuth 2.0" as the type. Then, click on "Get New Access Token" and fill in the required fields, such as the authorization URL, token URL, client ID, and client secret.

Can the authorization server choose to generate a new refresh token? ›

If you do not get back a new refresh token, then it means your existing refresh token will continue to work when the new access token expires. The most secure option is for the authorization server to issue a new refresh token each time one is used.

How do refresh and access tokens work? ›

An access token and a refresh token are issued if it's legitimate. The client must securely store this refresh token. The client can now request the resource server for secured resource access like API, and the resource server validates the access token. If it's valid, it returns the desired resource.

Top Articles
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5824

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.