Whisk Docs
Whisk HomeHelp CenterDeveloper Tools
v2.0.0
v2.0.0
  • The Whisk Platform
  • Whisk API Overview
    • Introduction
    • Integration
    • Authentication
      • Server Token
      • User Access Token
        • Auth Flow Example
      • Client Token
      • Anonymous Access from Client Apps
    • Whisk Sandbox
    • Getting Started
  • Whisk API Reference 2.0
    • Provisioning
      • Get provisioning
    • Autocomplete
    • Community
      • Get your Communities
      • Get Communities from a Topic
      • Discover Recommended Communities
      • Search Communities
      • Get a Community
      • Get Recipes from a Community
      • Add Recipes to a Community
      • Remove a Recipe from a Community
      • Join a Community
      • Leave a Community
    • Posts and Reviews
      • Get reviews for a recipe
      • Create or edit review
      • Create a Post
      • Get Post by id
      • Delete a Post
      • Edit a Post
      • Report a Post
      • Create a Post Reply
      • Get Post Replies
      • Delete a Post reply
      • Report a Post reply
      • Like a Post or Reply
      • Users who liked a Post or Reply
    • Public profiles
      • Hide recipe in Public profile
      • Get Recipes for Public Profile
      • Get User's public profile by user_id
      • Get User's public profile by username
    • Custom Label
    • Feed
      • Obtain a Recipe Feed
    • Food DB
      • Autocomplete
      • Search
      • Get Food
    • Food List
    • Food Log
    • Foodpairing
    • Healthy meal recommendations
      • Healthy recipe only recommendations for DA
      • Recipe recommendations for SH
      • Tailored Plan API request for Samsung TV
    • Meal Plan
      • Generate a Meal Plan
      • Meal Object
        • Get Meals
        • Delete Meal
        • Add a Meal
      • Meal Plan Settings Object
        • Get Meal Plan Settings
        • Update Meal Plan Settings
      • Meal Plan Batch
    • Recipe
      • Get a Recipe
      • Search a Recipe
      • User Recipes & Collections
        • Add User Recipe
        • Create A Recipe
        • Update External Recipe
        • Get All User Recipes
        • Update User Recipe
        • Remove Recipe from Favorites
        • Create Collection
        • Get All User Collections
        • Get Collection
        • Get Recipes from a Collection
        • Remove Collection
        • Get Smart Collection
        • Get Recipes from a Smart Collection
    • Shopping List
      • Get your Shopping Lists
      • Get a Shopping List
      • Create a Shopping List
      • Delete a Shopping List
      • Update basic details of a Shopping List
      • Move Items between Shopping Lists
      • Add Items to a Shopping List
      • Delete an Item from a Shopping List
      • Update an Item in a Shopping List
      • Clear Items from a Shopping List
    • Media
    • Store Item
    • Unit Conversion
    • Users
      • Get a User
      • Update User Settings using Patch
      • Update User Settings using Post
    • Try it out!
  • Shopping List SDK
    • Overview
    • Examples
      • Shoppable Recipes
      • Shoppable Products
      • Shoppable Media
    • Basic Setup
      • Basic Setup
      • Methods
      • Event Listeners
      • Widget
      • Subscriptions
      • Global Configuration
      • UTM Parameters
      • Using With SPA
  • Shopping List Mobile API
    • Overview
    • Examples
    • Reference
  • API Resources
    • Authentication Scopes
    • Errors and Troubleshooting
    • Cursor Pagination
    • Limits
    • Nutrients
    • Recipe Labels
    • Filtering Recipes using Custom Labels
    • Health Score, Glycemic Index, Glycemic Load
    • Whisk User Data
    • Integrated Retailers
    • Optimizing Image Load
    • Meal Plan
Powered by GitBook
On this page
  • Code Grant
  • Step 1: User Authorization
  • Step 2: Receive redirect
  • Step 3: Get an access token
  • Refreshing Tokens
  • Implicit Grant
  • Use bearer token

Was this helpful?

  1. Whisk API Overview
  2. Authentication

User Access Token

A user access token authorizes you to read, modify or write data on behalf of a specific Whisk user.

PreviousServer TokenNextAuth Flow Example

Last updated 4 years ago

Was this helpful?

Whisk supports OAuth 2.0 flow for generating user access token to authorize API requests.

OAuth 2.0 is a specification outlined in that allows third-party services to make requests on behalf of a user without accessing the passwords and other sensitive information. You can get familiar with OAuth 2.0 using .

Code Grant

The authorization code grant is used when an application exchanges an authorization code for an access token. After the user returns to the application via the redirect URL, the application will get the authorization code from the URL and use it to request an access token.

Step 1: User Authorization

First, the user has to grant you app permission to access their data or do actions on their behalf. Whisk provides an authorization page where users can securely sign in using their Whisk credentials or third-party accounts like Google, Facebook, etc. to grant permissions. This authorization page is accessed using the authorization URL.

Authorization URL

https://login.whisk.com/oauth/v2/authorize

To ensure that the driver grants permissions properly, you must append the query parameters to the authorization URL as described below.

https://login.whisk.com/oauth/v2/authorize?scope=<REQUESTED_SCOPES>&client_id=<CLIENT_ID>&response_type=code&redirect_uri=<REDIRECT_URI>

Parameter

Description

scope

This parameter indicates the parts of the user's data that you wish to access. You can also request multiple scopes separated by space or comma.

client_id

The client ID of your application.

response_type

OAuth 2.0 response type. The only option supported at the moment is code.

redirect_uri

The URL to redirect the resource owner to after authorization.

state (optional)

An arbitrary string value that will be passed back to your redirect URI. This parameter should be used to protect against cross-site request forgery (CSRF)

identity_provider (optional)

If provided, the authorization process is immediately forwarded to the specified identity provider (e.g. Google, Facebook)

After you’ve supplied the needed parameters, present this authorization URL as a link for the user to visit.

Step 2: Receive redirect

GET https://your-redirect-uri/?code=<AUTHORIZATION_CODE>

This is the authorization code you need for the next step.

In order for the redirect to work correctly, Whisk must approve the URL. For this, you must contact support in the dashboard.

Step 3: Get an access token

Use the Token Exchange URL to exchange the authorization code for an access_token which will allow you to make requests on behalf of the user.

Exchange Token URL

https://login.whisk.com/oauth/v2/token

Example Request:

curl "https://login.whisk.com/oauth/v2/token" \
  -F "client_id=<CLIENT_ID>" \
  -F "client_secret=<CLIENT_SECRET>" \
  -F "grant_type=authorization_code" \
  -F "redirect_uri=<REDIRECT_URI>" \
  -F "code=<AUTHORIZATION_CODE_FROM_STEP_2>"

Parameter

Description

client_id

The Client ID of your application.

client_secret

The Client Secret of your application.

grant_type

This should be set to authorization_code.

redirect_uri

code

Example Response:

{
  "access_token": "Xb609ErrcoRNwll9wwxbk70OxFrbxEOu8Ui8ZzV4yJDA9RvLRGFhlMAAfkP2OmSS",
  "token_type": "Bearer",
  "expires_in": 2592000,
  "scope": [
    "cookbook:write"
  ],
  "refresh_token": "oS1437tty6buHTef0VGkXgcR7PvOt2DDUntSjWaCtDqJX8osK7d3Mip38NjpJdTH"
}

The access_token is valid for the time described by expires_in (in seconds). The refresh_token expires after one year and can be used to obtain a new access_token at any time given provided your application is still authorized to access the API on behalf of this user.

The scope in the token response indicates what access was actually granted by user.

The access_token retrieved from authenticating a user account stays active even when a user changes the account password or other account details.

Refreshing Tokens

If you requested the access token with the offline_accessscope, the response will include a refresh_tokenwhich can be used to refresh the access token. When the user’s access_tokenhas expired, you can obtain a new access_tokenby exchanging the refresh_tokenassociated with the access_tokenusing the Token Exchange URL.

Refreshing the user access token means that you don’t need to ask the user to authorize your app for the same permissions again (offline_access).

curl "https://login.whisk.com/oauth/v2/token" \
  -d "client_id=<CLIENT_ID>" \
  -d "client_secret=<CLIENT_SECRET>" \
  -d "grant_type=refresh_token" \
  -d "refresh_token=<REFRESH_TOKEN>"

A refresh_tokenis valid for one year and tokens that have been inactive for more than one year will be invalidated.

Implicit Grant

First, the user has to grant your app permission to access their data or do actions on their behalf. Whisk provides an authorization page where users can securely sign in with their Whisk username and password or accounts from other providers (Google, Facebook, etc.) to grant permissions. This authorization page is accessed through the authorization URL. To ensure that the driver grants permissions to your app properly, supply query parameters to that URL as described below.

https://login.whisk.com/oauth/v2/authorize?client_id=<CLIENT_ID>&response_type=token&redirect_uri=<REDIRECT_URI>

Parameter

Description

response_type

OAuth 2.0 response type. token

client_id

The client ID of your application.

redirect_uri

The URI we will redirect back to after authorization by the resource owner.

state(optional)

State which will be passed back to you to prevent tampering.

identity_provider (optional)

If provided, the authorization process is immediately forwarded to the specified identity provider (e.g. Google, Facebook)

After you’ve supplied the needed parameters, present this authorization URL as a link for the user to visit.

Unlike the authorization code grant type, in which the client makes separate requests for authorization and for an access token, the client receives the access token as the result of the authorization request.

Once the Whisk user authenticates and authorizes your app, Whisk will issues an access token and delivers it by adding the following parameters to the fragment component of the redirection URI using the application/x-www-form-urlencoded format

Example Response:

http://example.com/#access_token=Xb609ErrcoRNwll9wwxbk70OxFrbxEOu8Ui8ZzV4yJDA9RvLRGFhlMAAfkP2OmSS&state=xyz&token_type=Bearer&expires_in=86400

The access_tokenis valid for the time described by expires_in(in seconds). The refresh_tokendoes not return.

The access_tokenretrieved from authenticating a user account will stay active even when a user changes the account password or other account details.

Use bearer token

You can pass the access_token returned in the previous steps as a bearer token in the Authorization header, or pass it in as a query parameter in the URL.

Here is how you pass it in a header:

curl "https://api.whisk.com/v2/me" \
  -H "Authorization: Bearer <Access-Token>"

To see the full list of supported scopes, read .

Once the Whisk user authenticates and authorizes your app, Whisk will issue an HTTP 302 redirect to the redirect_uri passed in . On that redirect, you will receive a single-use authorization code that expires in 1 day.

The base of the URI must match the redirect_uri used in .

The authorization code from .

Implicit flow is the less secure approach. We recommend you to consider flow instead.

RFC 6749
Aaron Parecki’s "OAuth 2 Simplified" guide
Step 1
Code Grant
Authentication Scopes
Step 1
Step 2