MCPcopy Index your code
hub / github.com/callstack/agent-device / resolveRemoteAuth

Function resolveRemoteAuth

src/cli/auth-session.ts:93–143  ·  view source on GitHub ↗
(options: {
  command: string;
  flags: CliFlags;
  stateDir: string;
  allowInteractiveLogin: boolean;
  env?: EnvMap;
  io?: AuthIo;
})

Source from the content-addressed store, hash-verified

91}
92
93export async function resolveRemoteAuth(options: {
94 command: string;
95 flags: CliFlags;
96 stateDir: string;
97 allowInteractiveLogin: boolean;
98 env?: EnvMap;
99 io?: AuthIo;
100}): Promise<RemoteAuthResolution> {
101 const env = options.env ?? options.io?.env ?? process.env;
102 if (!options.flags.daemonBaseUrl) return { flags: options.flags, source: 'none' };
103 if (hasToken(options.flags.daemonAuthToken)) return { flags: options.flags, source: 'flag' };
104 if (hasToken(env.AGENT_DEVICE_DAEMON_AUTH_TOKEN)) {
105 return { flags: options.flags, source: 'env' };
106 }
107 if (!shouldUseCloudAuth(options.flags.daemonBaseUrl, env)) {
108 return { flags: options.flags, source: 'none' };
109 }
110
111 const sessionAccess = await resolveCliSessionAccess({
112 stateDir: options.stateDir,
113 flags: options.flags,
114 env,
115 io: options.io,
116 });
117 if (sessionAccess) {
118 return {
119 flags: { ...options.flags, daemonAuthToken: sessionAccess.accessToken },
120 source: 'cli-session',
121 };
122 }
123
124 if (!options.allowInteractiveLogin) {
125 if (options.flags.noLogin) {
126 throw new AppError('UNAUTHORIZED', 'Remote daemon authentication is required.', {
127 hint: 'Run agent-device auth login, unset --no-login, or set AGENT_DEVICE_DAEMON_AUTH_TOKEN.',
128 });
129 }
130 throw buildNonInteractiveLoginError(options.command, env);
131 }
132
133 const login = await loginWithDeviceAuth({
134 stateDir: options.stateDir,
135 flags: options.flags,
136 env,
137 io: options.io,
138 });
139 return {
140 flags: { ...options.flags, daemonAuthToken: login.accessToken },
141 source: 'login',
142 };
143}
144
145export async function resolveCloudAccessForConnect(options: {
146 stateDir: string;

Callers 2

resolveRemoteAuthForCliFunction · 0.85

Calls 5

hasTokenFunction · 0.85
shouldUseCloudAuthFunction · 0.85
resolveCliSessionAccessFunction · 0.85
loginWithDeviceAuthFunction · 0.85

Tested by

no test coverage detected