MCPcopy Create free account
hub / github.com/Noumena-Network/code / getAuthHeaders

Function getAuthHeaders

src/utils/http.ts:73–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71 * Returns either OAuth headers for Max/Pro users or API key headers for regular users
72 */
73export function getAuthHeaders(): AuthHeaders {
74 const session = getAuthRuntime().getCurrentSession()
75
76 if (session.principalSource === 'managed_oauth') {
77 if (session.sessionState !== 'usable' || !session.accessToken) {
78 return {
79 headers: {},
80 error: 'No usable OAuth token available',
81 }
82 }
83 return {
84 headers: {
85 Authorization: `Bearer ${session.accessToken}`,
86 'anthropic-beta': OAUTH_BETA_HEADER,
87 },
88 }
89 }
90
91 if (
92 (session.principalSource === 'service_oauth_env' ||
93 session.principalSource === 'service_oauth_fd' ||
94 session.principalSource === 'external_bearer_compat') &&
95 session.accessToken
96 ) {
97 return {
98 headers: {
99 Authorization: `Bearer ${session.accessToken}`,
100 'anthropic-beta': OAUTH_BETA_HEADER,
101 },
102 }
103 }
104
105 if (
106 (session.principalSource === 'direct_api_key_env' ||
107 session.principalSource === 'console_api_key' ||
108 session.principalSource === 'api_key_helper') &&
109 session.rawApiKeySource !== 'OPENAI_API_KEY' &&
110 session.apiKey
111 ) {
112 return {
113 headers: {
114 'x-api-key': session.apiKey,
115 },
116 }
117 }
118
119 return {
120 headers: {},
121 error:
122 session.principalSource === 'managed_oauth' ||
123 session.headersKind === 'bearer'
124 ? 'No usable OAuth token available'
125 : 'No API key available',
126 }
127}
128
129/**
130 * Wrapper that handles OAuth 401 errors by force-refreshing the token and

Callers 8

runProtectedRequestFunction · 0.70
generateSessionTitleFunction · 0.70
fetchCcsharePayloadFunction · 0.70
submitTranscriptShareFunction · 0.50
doExportMethod · 0.50
refreshModelCapabilitiesFunction · 0.50

Calls 2

getAuthRuntimeFunction · 0.85
getCurrentSessionMethod · 0.65

Tested by 1

runProtectedRequestFunction · 0.56