Introduction

The Device Flow is an OAuth 2.0 authorization flow designed for devices that lack a web browser or have limited input capabilities, such as smart TVs, IoT devices, gaming consoles, and CLI applications. Unlike traditional OAuth flows that rely on redirects, the Device Flow enables users to authenticate by entering a code on a separate device with a browser.

Learning Objectives

By the end of this blog, you will:

What is Device Flow?

The Device Flow is a mechanism in OAuth 2.0 that allows devices without an interactive browser to securely obtain access tokens. Instead of direct user authentication on the device, a separate device (such as a mobile phone or computer) is used to authorize the request.

Why Use Device Flow?

When to Use Device Flow?


Where is Device Flow Used in Salesforce?

Salesforce supports the Device Flow for connected apps. It allows users to log in on a different device and grant access without requiring a direct browser-based authentication on the requesting device.


How Does Device Flow Work?

Step-by-Step Process:

  1. Device Requests Authorization
    • The device sends a request to Salesforce’s authorization server with the client ID.
    • Salesforce responds with a device code and a user verification URL.
  2. User Authentication on a Separate Device
    • The user opens the provided URL on a browser-enabled device (e.g., mobile or computer).
    • They enter the user code displayed on the device.
  3. Salesforce Prompts for Login
    • If the user is not logged in, Salesforce asks them to sign in.
    • If already authenticated, Salesforce asks for approval to grant access.
  4. Device Polls Salesforce for Token
    • The device continuously polls Salesforce using the device code.
    • Once the user approves access, Salesforce responds with an access token.
  5. Access Token is Used
    • The device uses the access token to call Salesforce APIs.
    • It remains valid until expiration or revocation.

Advantages and disadvantages

advantages

disadvantages


Common Mistakes and Tips

Summary


Quiz or Self-Assessment

  1. What type of devices benefit the most from Device Flow?
    a) Laptops
    b) IoT devices
    c) Web browsers
    d) Mobile apps
  2. How does the device get an access token in Device Flow?
    a) The user enters their credentials on the device
    b) The device sends the user code and waits for approval
    c) The device generates an access token on its own
  3. What happens if the user does not approve the request in time?
    a) The device automatically gets an access token
    b) The request expires, and the process must restart
    c) The user is logged in automatically

(Answers: 1-b, 2-b, 3-b)


Conclusion

The Device Flow is an essential OAuth 2.0 mechanism for authenticating devices with limited input capabilities. By delegating authentication to a separate device, Salesforce ensures a secure and user-friendly login process for IoT, CLI, and smart devices.

Additional Resources

https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_web_server_flow.htm&type=5