Skip to content

Commit

Permalink
Make device auth the default authentication method
Browse files Browse the repository at this point in the history
  • Loading branch information
shauns committed Jun 19, 2024
1 parent 1f919e8 commit f76debd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-walls-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': minor
---

Device auth is the default authentication method
1 change: 1 addition & 0 deletions packages/cli-kit/src/private/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const environmentVariables = {
alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',
alwaysLogMetrics: 'SHOPIFY_CLI_ALWAYS_LOG_METRICS',
deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',
accessCodeAuth: 'SHOPIFY_CLI_ACCESS_CODE_AUTH',
enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',
env: 'SHOPIFY_CLI_ENV',
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
Expand Down
15 changes: 14 additions & 1 deletion packages/cli-kit/src/public/node/context/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,26 @@ describe('useDeviceAuth', () => {
expect(got).toBe(true)
})

test('returns false when SHOPIFY_CLI_DEVICE_AUTH, SPIN, CODESPACES or GITPOD_WORKSPACE_URL are missing', () => {
test('returns true by default', () => {
// Given
const env = {}

// When
const got = useDeviceAuth(env)

// Then
expect(got).toBe(true)
})

test('returns false if opted-out', () => {
// Given
const env = {
SHOPIFY_CLI_ACCESS_CODE_AUTH: '1',
}

// When
const got = useDeviceAuth(env)

// Then
expect(got).toBe(false)
})
Expand Down
8 changes: 7 additions & 1 deletion packages/cli-kit/src/public/node/context/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ export function firstPartyDev(env = process.env): boolean {
/**
* Returns true if the CLI should use device auth.
*
* Device auth can be opted out by using SHOPIFY_CLI_ACCESS_CODE_AUTH.
*
* @param env - The environment variables from the environment of the current process.
* @returns True if SHOPIFY_CLI_DEVICE_AUTH is truthy or the CLI is run from a cloud environment.
*/
export function useDeviceAuth(env = process.env): boolean {
return isTruthy(env[environmentVariables.deviceAuth]) || isCloudEnvironment(env)
return (
!isTruthy(env[environmentVariables.accessCodeAuth]) ||
isTruthy(env[environmentVariables.deviceAuth]) ||
isCloudEnvironment(env)
)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function getBackendPort(): number | undefined {
}

/**
* Returns the information of the identity token.
* Returns the information of the identity & refresh tokens, provided by environment variables.
*
* @returns The identity token information in case it exists.
*/
Expand Down

0 comments on commit f76debd

Please sign in to comment.