oracle/oci-typescript-sdk

Using SDK with Next.js (Authentication)

Opened this issue · 1 comments

Hi Team,

Thanks for your effort in enabling the oci in javascript.

I've come across a slight issue when trying to implement the SDK in my Next.js project (in server action).
I just can't get my head around on how to configure the credentials using the config files.. which I assume it has something to do with path / incompatibility.

At the moment I'm using SimpleAUthenticationDetailsProvider as the alternative, but if possible, I'd rather use the config files as I believe it to be safer option.

For anyone wondering my current implementation, see below.

"use server";

import * as objectstorage from "oci-objectstorage";
import * as common from "oci-common"; 
// do not import common from "oci-common"

const tenancy: string = process.env.ORACLE_TENANCY as string;
const user: string = process.env.ORACLE_USER as string;
const fingerprint: string = process.env.ORACLE_FINGERPRINT as string;
// const passphrase: string | null = null; // optional parameter
const privateKey: string = process.env.ORACLE_PEM as string;
const region: common.Region = common.Region.AP_MELBOURNE_1; // Change to appropriate region

const provider = new common.SimpleAuthenticationDetailsProvider(
  tenancy,
  user,
  fingerprint,
  privateKey,
  null,
  region
);

// using the client with provider
const client = new objectstorage.ObjectStorageClient({
      authenticationDetailsProvider: provider,
});

Hi @ksi9302. Could you share what problem exactly you are having with config files? Here are 2 good pieces of documentation that should help you get started with them:
https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm
https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/typescriptsdkgettingstarted.htm#configuring
Small note, you do not need to pass in configProfile or configurationFilePath to ConfigFileAuthenticationDetailsProvider if you use the default config path of ~/.oci/config and default profile name of [DEFAULT]. Hope this helps!