@Micheal Palliparambil , to set up an Interactive Browser Client with Next.js, you can follow these steps:
- Install the required packages using npm:
npm install @azure/identity
- Import the required packages in your Next.js page:
import { InteractiveBrowserCredential } from '@azure/identity';
- Create a new instance of the
InteractiveBrowserCredential
class:
const interactiveCredential = new InteractiveBrowserCredential({
redirectUri: 'http://localhost:3000',
});
- Use the
getToken
method of theInteractiveBrowserCredential
class to get an access token:
const token = await interactiveCredential.getToken('https://database.windows.net/.default');
Here is the complete code for your reference:
import { InteractiveBrowserCredential } from '@azure/identity';
async function myfunc() {
const interactiveCredential = new InteractiveBrowserCredential({
redirectUri: 'http://localhost:3000',
});
const token = await interactiveCredential.getToken('https://database.windows.net/.default');
// Use the token to make API calls
}
Note that the InteractiveBrowserCredential
class requires a user to sign in interactively, so this approach is not suitable for non-interactive scenarios. If you need to authenticate a service principal, you should use a different credential type, such as ClientSecretCredential
.More information can be found here.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James