mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Azure OpenAI Chat Model Node): Simplify Azure Entra ID Authentication and Auto-Refresh token (#15335)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import type { TokenCredential, AccessToken } from '@azure/identity';
|
||||
import type { ClientOAuth2TokenData } from '@n8n/client-oauth2';
|
||||
import { ClientOAuth2 } from '@n8n/client-oauth2';
|
||||
import type { INode } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
@@ -20,10 +22,25 @@ export class N8nOAuth2TokenCredential implements TokenCredential {
|
||||
if (!this.credential?.oauthTokenData?.access_token) {
|
||||
throw new NodeOperationError(this.node, 'Failed to retrieve access token');
|
||||
}
|
||||
const oAuthClient = new ClientOAuth2({
|
||||
clientId: this.credential.clientId,
|
||||
clientSecret: this.credential.clientSecret,
|
||||
accessTokenUri: this.credential.accessTokenUrl,
|
||||
scopes: this.credential.scope?.split(' '),
|
||||
authentication: this.credential.authentication,
|
||||
authorizationUri: this.credential.authUrl,
|
||||
additionalBodyProperties: {
|
||||
resource: 'https://cognitiveservices.azure.com/',
|
||||
},
|
||||
});
|
||||
|
||||
const token = await oAuthClient.credentials.getToken();
|
||||
const data = token.data as ClientOAuth2TokenData & {
|
||||
expires_on: number;
|
||||
};
|
||||
return {
|
||||
token: this.credential.oauthTokenData.access_token,
|
||||
expiresOnTimestamp: this.credential.oauthTokenData.expires_on,
|
||||
token: data.access_token,
|
||||
expiresOnTimestamp: data.expires_on,
|
||||
};
|
||||
} catch (error) {
|
||||
// Re-throw with better error message
|
||||
|
||||
Reference in New Issue
Block a user