@@ -54,9 +54,17 @@ export type TigrisStorageConfig = {
5454 organizationId ?: string ;
5555 iamEndpoint ?: string ;
5656 authDomain ?: string ;
57+ credentialProvider ?: ( ) => Promise < {
58+ accessKeyId : string ;
59+ secretAccessKey : string ;
60+ sessionToken ?: string ;
61+ expiration ?: Date ;
62+ } > ;
5763} ;
5864
59- export async function getStorageConfig ( ) : Promise < TigrisStorageConfig > {
65+ export async function getStorageConfig ( options ?: {
66+ withCredentialProvider ?: boolean ;
67+ } ) : Promise < TigrisStorageConfig > {
6068 // 1. AWS profile (only if AWS_PROFILE is set)
6169 if ( hasAwsProfile ( ) ) {
6270 const profile = process . env . AWS_PROFILE || 'default' ;
@@ -78,7 +86,6 @@ export async function getStorageConfig(): Promise<TigrisStorageConfig> {
7886
7987 if ( loginMethod === 'oauth' ) {
8088 const authClient = getAuthClient ( ) ;
81- const accessToken = await authClient . getAccessToken ( ) ;
8289 const selectedOrg = getSelectedOrganization ( ) ;
8390
8491 if ( ! selectedOrg ) {
@@ -88,9 +95,20 @@ export async function getStorageConfig(): Promise<TigrisStorageConfig> {
8895 }
8996
9097 return {
91- sessionToken : accessToken ,
98+ sessionToken : await authClient . getAccessToken ( ) ,
9299 accessKeyId : '' ,
93100 secretAccessKey : '' ,
101+ // Only include credentialProvider for long-running operations (uploads)
102+ // that need token refresh. Short-lived operations (ls, rm, head) use
103+ // the static sessionToken above and benefit from S3Client caching.
104+ ...( options ?. withCredentialProvider && {
105+ credentialProvider : async ( ) => ( {
106+ accessKeyId : '' ,
107+ secretAccessKey : '' ,
108+ sessionToken : await authClient . getAccessToken ( ) ,
109+ expiration : new Date ( Date . now ( ) + 10 * 60 * 1000 ) ,
110+ } ) ,
111+ } ) ,
94112 endpoint : tigrisConfig . endpoint ,
95113 organizationId : selectedOrg ,
96114 iamEndpoint : tigrisConfig . iamEndpoint ,
@@ -132,7 +150,7 @@ export async function getStorageConfig(): Promise<TigrisStorageConfig> {
132150
133151 // No valid auth method found — try auto-login in interactive terminals
134152 if ( await triggerAutoLogin ( ) ) {
135- return getStorageConfig ( ) ;
153+ return getStorageConfig ( options ) ;
136154 }
137155 throw new Error (
138156 'Not authenticated. Please run "tigris login" or "tigris configure" first.'
@@ -164,7 +182,6 @@ export async function getS3Client(): Promise<S3Client> {
164182
165183 if ( loginMethod === 'oauth' ) {
166184 const authClient = getAuthClient ( ) ;
167- const accessToken = await authClient . getAccessToken ( ) ;
168185 const selectedOrg = getSelectedOrganization ( ) ;
169186
170187 if ( ! selectedOrg ) {
@@ -173,14 +190,17 @@ export async function getS3Client(): Promise<S3Client> {
173190 ) ;
174191 }
175192
193+ const credentialProvider = async ( ) => ( {
194+ accessKeyId : '' ,
195+ secretAccessKey : '' ,
196+ sessionToken : await authClient . getAccessToken ( ) ,
197+ expiration : new Date ( Date . now ( ) + 10 * 60 * 1000 ) ,
198+ } ) ;
199+
176200 const client = new S3Client ( {
177201 region : 'auto' ,
178202 endpoint : tigrisConfig . endpoint ,
179- credentials : {
180- sessionToken : accessToken ,
181- accessKeyId : '' , // Required by SDK but not used with token auth
182- secretAccessKey : '' , // Required by SDK but not used with token auth
183- } ,
203+ credentials : credentialProvider ,
184204 } ) ;
185205
186206 // Add middleware to inject custom headers
0 commit comments