Power Platform CLI | Authenticate environment using device code
For unversed, Microsoft Power Platform CLI is a developer CLI that empowers developers and ISVs to perform various operations related to environment lifecycle, authentication, and work with Dataverse environments, solution packages, portals, code components, and so on.
In this blog post, lets see how to connect to an Environment using Power CLI ‘Device Code’ authentication option.
Using CLI:
- Open Command Prompt.
- Execute pac command to make sure the Power Platform CLI is installed on your machine. You get following screen, if CLI is already installed.
- If not installed, Download and install Microsoft Power Platform CLI.
- Now to connect to Power platform environment, we can use following pac auth create command by passing either Username & Password or ApplicationID & ClientSecret combination.
pac auth create [--name] [--kind] [--url] [--username] [--password] [--applicationId] [--clientSecret] [--tenant] [--cloud] [--deviceCode]
- We can also authenticate using ‘deviceCode’, which I will explain in next section.
Authenticate using Device Code:
Now we can also authenticate to an environment by generating a ‘Device Code’ as mentioned in steps below.
- From console, run following pac auth create command
pac auth create --url https://{your environment}.crm.dynamics.com -dc
- You would get a notification with ‘Device Code‘, “To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code RXXXXZ to authenticate.“
- Copy the ‘Device Code‘ (i.e., RXXXXZ in my case) and hit https://microsoft.com/devicelogin url in a browser.
- Provide the code and click ‘Next’.
- Complete the sign in by providing your credentials.
- You will get following message post successful authentication.
- Now you can close the browser and good to start executing pac cli commands from console.
Key Points:
- Currently, Microsoft Power Platform standalone CLI is supported only on Windows 10 and Windows 11.
- Power Platform Tools for Visual Studio Code is available on Windows 10, Windows 11, Linux, and MacOS.
🙂
Categories: PowerApps
CLI, Device Code, PAC, Power Apps
Comments (0)
Trackbacks (0)
Leave a comment
Trackback