Managing access tokens, bearer tokens, access_token, refresh_token - Machine Learning Server (2024)

  • Article

Important

This content is being retired and may not be updated in the future. The support for Machine Learning Server will end on July 1, 2022. For more information, see What's happening to Machine Learning Server?

Applies to: Machine Learning Server, Microsoft R Server 9.x

Machine Learning Server, formerly known as Microsoft R Server, uses tokens to identify and authenticate the user who is sending the API call within your application. Users must authenticate when making an API call. They can do so with the 'POST /login HTTP/1.1' API call, after which Machine Learning Server issues a bearer token to your application for this user. Alternately, if the organization is using Azure Active Directory (AAD), users receive a bearer token from AAD when they authenticate.

This bearer token is a lightweight security token that grants the “bearer” access to a protected resource, in this case, Machine Learning Server's core APIs for operationalizing analytics. After a user has been authenticated, the application must validate the user’s bearer token to ensure that authentication was successful.

Important

For proper access token signing and verification across your configuration, ensure that the JWT settings are exactly the same for every web node. These JWT settings are defined on each web node in the configuration file, appsetting.json. Check with your administrator. Learn more...

Security Concerns

Despite the fact that a party must first authenticate to receive the token, tokens can be intercepted by an unintended party if the token is not secured in transmission and storage. While some security tokens have a built-in mechanism to protect against unauthorized parties, these tokens do not and must be transported in a secure channel such as transport layer security (HTTPS).

If a token is transmitted in the clear, a man-in the middle attack can be used by a malicious party to acquire the token to make an unauthorized access to a protected resource. The same security principles apply when storing or caching tokens for later use. Always ensure that your application transmits and stores tokens in a secure manner.

You can revoke a token if a user is no longer permitted to make requests on the API or if the token has been compromised.


Create tokens

The API bearer token's properties include an access_token / refresh_token pair and expiration dates.

Tokens can be generated in one of two ways:

  • If Active Directory LDAP or a local administrator account is enabled, then send a 'POST /login HTTP/1.1' API request to retrieve the bearer token.

  • If Azure Active Directory (AAD) is enabled, then the token comes from AAD.

Learn more about these authentication methods.

Example: Token creation request

  • Request

    POST /login HTTP/1.1{ "username": "my-user-name", "password": "$ecRetPas$1"}
  • Response

    { "token_type":"Bearer", "access_token":"eyJhbGci....", "expires_in":3600, "expires_on":1479937454, "refresh_token":"0/LTo...."}

Token Lifecycle

The bearer token is made of an access_token property and a refresh_token property.

The "access_token" LifecycleThe "refresh_token" Lifecycle
Gets
Created
Whenever the user logs in, or

a refreshToken api is called

Whenever the user logs in
ExpiresAfter 1 hour (3660 seconds) of inactivityAfter 336 hours (14 days) of inactivity
Becomes
Invalid
If the refresh_token was revoked, or

If not used for 336 hours (14 days), or

When a new pair of access_token/refresh_token has been created

If not used for 336 hours (14 days), or

When the refresh_token expires, or

When a new access_token/refresh_token pair was created, or

If the refresh_token was revoked

Use tokens

As defined by HTTP/1.1 [RFC2617], the application should send the access_token directly in the Authorization request header.

You can do so by including the bearer token's access_token value in the HTTP request body as 'Authorization: Bearer {access_token_value}'.

When the API call is sent with the token, Machine Learning Server attempts to validate that the user is successfully authenticated and that the token itself is not expired.

  • If an authenticated user has a bearer token's access_token or refresh_token that is expired, then a '401 - Unauthorized (invalid or expired refresh token)' error is returned.

  • If the user is not successfully authenticated, a '401 - Unauthorized (invalid credentials)' error is returned.

Examples

Example HTTP header for session creation:

 POST /sessions HTTP/1.1 Host: mrs.contoso.com Authorization: Bearer eyJhbGci.... ...

Example HTTP header for publishing web service:

 POST /api/{service}/{version} HTTP/1.1 Host: mrs.contoso.com Authorization: Bearer eyJhbGci.... ...

Renew tokens

A valid bearer token (with active access_token or refresh_token properties) keeps the user's authentication alive without requiring him or her to re-enter their credentials frequently.

The access_token can be used for as long as it’s active, which is up to one hour after login or renewal. The refresh_token is active for 336 hours (14 days). After the access_token expires, an active refresh_token can be used to get a new access_token / refresh_token pair as shown in the following example. This cycle can continue for up to 90 days after which the user must log in again. If the refresh_token expires, the tokens cannot be renewed and the user must log in again.

To refresh a token, use the 'POST /login/refreshToken HTTP/1.1' API call.

Example: Refresh access_token

  • Example request:

    POST /login/refreshToken HTTP/1.1 Connection: Keep-Alive Content-Type: application/json; charset=utf-8 Accept-Encoding: gzip, deflate Content-Length: 370 Host: mrs.contoso.com { "refreshToken": "0/LTo...." }
  • Example response:

    { "token_type":"Bearer", "access_token":"eyJhbGci....", "expires_in":3600, "expires_on":1479937523, "refresh_token":"ScW2t...."}

Revoke refresh tokens

A refresh_token should be revoked:

  • If a user is no longer permitted to make requests on the API, or
  • If the access_token or refresh_token have been compromised.

Use the 'DELETE /login/refreshToken?refreshToken={refresh_token_value} HTTP/1.1' API call to revoke a token.

Example: Revoke token

  • Example request:

    DELETE https://mrs.contoso.com/login/refreshToken?refreshToken=ScW2t HTTP/1.1 Connection: Keep-Alive Accept-Encoding: gzip, deflate Host: mrs.contoso.com
  • Example response:

    HTTP 200 Success
Managing access tokens, bearer tokens, access_token, refresh_token - Machine Learning Server (2024)

FAQs

How do I refresh my access token with access 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.

What is bearer token vs 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.

How to handle bearer tokens? ›

How to Add and Pass Bearer Token in Header
  1. Get the Bearer Token. First, you need to obtain a valid bearer token to use in the header. ...
  2. Make an HTTP Request with a Bearer Token. In Apidog, make an HTTP GET or POST request by clicking the "+" button. ...
  3. Add the Header to the Request. ...
  4. Send the Header Request and Response returned.

What is bearer token and access token? ›

Bearer Tokens are the predominant type of access token used with OAuth 2.0. A Bearer Token is an opaque string, not intended to have any meaning to clients using it. Some servers will issue tokens that are a short string of hexadecimal characters, while others may use structured tokens such as JSON Web Tokens.

What is the difference between refresh and 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 access my access token? ›

How Do Access Tokens Work?
  1. Login: Use a known username and password to prove your identity.
  2. Verification: The server authenticates the data and issues a token.
  3. Storage: The token is sent to your browser for storage.
  4. Communication: Each time you access something new on the server, your token is verified once more.
Feb 14, 2023

What is the difference between token and access token? ›

The differences between ID Tokens and Access Tokens

ID Tokens are JSON Web Tokens (JWT) that contain claims about a user's identity, such as their username, email, etc. Access Tokens are used to grant applications permission to access server resources on behalf of the user.

What is an example of an access token? ›

For example, if your user authenticates using Facebook, the access token issued by Facebook can be used to call the Facebook Graph API. These tokens are controlled by the IdP and can be issued in any format.

What's the point of a refresh token? ›

When to use Refresh Tokens? The main purpose of using a refresh token is to considerably shorten the life of an access token. The refresh token can then later be used to authenticate the user as and when required by the application without running into problems such as cookies being blocked, etc.

How do I generate a Bearer Token? ›

How to Generate a Bearer Token? (GitHub Example )
  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.

What is the difference between API key and Bearer Token? ›

API key - A value provided by code when calling an API to identify and authorize the caller. It is intended to be used programmatically and is often a long string of letters and numbers. Token - A piece of data that represents a user session or specific privileges. Used by individual users for a limited period of time.

What is the difference between OAuth and Bearer Token? ›

Bearer tokens are for OAuth2 authentication. A bearer token is an encoded value that generally contains the user ID, authenticated token and a timetamp. It is most commonly used in REST APIs. If the API supports OAuth2 then it'll use a bearer token.

Who generates the bearer token? ›

The bearer token is a cryptic string, usually generated by the server in response to a login request. The client must send this token in the Authorization header when making requests to protected resources: Authorization: Bearer <token>

How to check bearer token? ›

If using bearer tokens, verify that the request is coming from Google and is intended for the the sender domain. If the token doesn't verify, the service should respond to the request with an HTTP response code 401 (Unauthorized) . Bearer Tokens are part of the OAuth V2 standard and widely adopted by Google APIs.

Where are bearer tokens stored? ›

There are two patterns for client-side storage of bearer tokens: cookies and using HTML5 local storage. If cookies are being used to transmit the bearer token from client to server, then cookies would also be used to store the bearer token on the client side.

Can an access token and refresh token be same? ›

Access tokens are temporary credentials that grant access to a protected resource, while refresh tokens are used to obtain new access tokens once the current ones expire.

How do I regenerate my personal access token? ›

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. To give your token an expiration, select Expiration, then choose a default option or click Custom to enter a date.

Where is access token and refresh token stored? ›

If your app needs to call APIs on behalf of the user, access tokens and (optionally) refresh tokens are needed. These can be stored server-side or in a session cookie. The cookie needs to be encrypted and have a maximum size of 4 KB.

Why is my refresh token invalid access token? ›

Problem: Refresh tokens can become invalid for a few reasons:
  1. There is a maximum of 25 refresh tokens that can be valid at a time. If someone gets a 26th refresh token, then the 1st refresh token becomes invalid.
  2. Refresh tokens can also be manually revoked. If someone left the company, then they might have done so.

Top Articles
How common is my birthday? Check out the full list of popular birthdays and months.
Coinvest Pay – Let's grow together
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Best Team In 2K23 Myteam
Dollywood's Smoky Mountain Christmas - Pigeon Forge, TN
Shs Games 1V1 Lol
25X11X10 Atv Tires Tractor Supply
Hay day: Top 6 tips, tricks, and cheats to save cash and grow your farm fast!
Mlifeinsider Okta
Gt Transfer Equivalency
What Does Dwb Mean In Instagram
Vichatter Gifs
Tracking Your Shipments with Maher Terminal
Nwi Arrests Lake County
Apne Tv Co Com
Mission Impossible 7 Showtimes Near Marcus Parkwood Cinema
Petco Vet Clinic Appointment
Scotchlas Funeral Home Obituaries
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Nurse Logic 2.0 Testing And Remediation Advanced Test
Melissababy
Barber Gym Quantico Hours
Best Transmission Service Margate
Reser Funeral Home Obituaries
پنل کاربری سایت همسریابی هلو
Suspiciouswetspot
Divide Fusion Stretch Hoodie Daunenjacke für Herren | oliv
Copper Pint Chaska
Spectrum Outage in Queens, New York
Narragansett Bay Cruising - A Complete Guide: Explore Newport, Providence & More
Infinite Campus Asd20
Vivification Harry Potter
Rubmaps H
Home Auctions - Real Estate Auctions
35 Boba Tea & Rolled Ice Cream Of Wesley Chapel
Xfinity Outage Map Lacey Wa
Www Craigslist Com Shreveport Louisiana
Goodwill Thrift Store & Donation Center Marietta Photos
No Hard Feelings Showtimes Near Tilton Square Theatre
Property Skipper Bermuda
Tirage Rapid Georgia
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Improving curriculum alignment and achieving learning goals by making the curriculum visible | Semantic Scholar
Carteret County Busted Paper
Grand Valley State University Library Hours
Pas Bcbs Prefix
Star Sessions Snapcamz
Westport gun shops close after confusion over governor's 'essential' business list
Parks And Rec Fantasy Football Names
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6569

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.