Skip to content

Commit

Permalink
added support for user assigned identity
Browse files Browse the repository at this point in the history
  • Loading branch information
dantelmomsft committed Nov 24, 2023
1 parent 7b2c81b commit 5c12f35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureCliCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.util.StringUtils;

@Configuration
public class AzureAuthenticationConfiguration {

@Value("${azure.identity.client-id}")
String clientId;

@Profile("dev")
@Bean
public TokenCredential localTokenCredential() {
Expand All @@ -20,6 +25,10 @@ public TokenCredential localTokenCredential() {
@Bean
@Profile("default")
public TokenCredential managedIdentityTokenCredential() {
return new ManagedIdentityCredentialBuilder().build();
if (this.clientId.equals("system-managed-identity"))
return new ManagedIdentityCredentialBuilder().build();
else
return new ManagedIdentityCredentialBuilder().clientId(this.clientId).build();

}
}
5 changes: 4 additions & 1 deletion app/backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ storage-account.service=${AZURE_STORAGE_ACCOUNT}
blob.container.name=${AZURE_STORAGE_CONTAINER:content}

logging.level.com.microsoft.openai.samples.rag.ask.approaches.semantickernel=DEBUG
server.error.include-message=always
server.error.include-message=always

# Support for User Assigned Managed identity
azure.identity.client-id=${AZURE_CLIENT_ID:system-managed-identity}

0 comments on commit 5c12f35

Please sign in to comment.