Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make device auth the default authentication method #4092

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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