Skip to content

Conversation

@4gust
Copy link
Collaborator

@4gust 4gust commented Sep 9, 2025

Fix panic in AcquireTokenSilent for public clients due to nil Credential

Description

This PR addresses a nil panic occurring during AcquireTokenSilent calls for public clients in the Microsoft Authentication Library for Go. #580

Root Cause

In apps/internal/base/base.go, the Token.Credential(...) function is called unconditionally within AcquireTokenSilent, even for public clients. This function expects a non-nil *accesstokens.Credential (specifically, silent.Credential), but for public clients, this value is nil.

The panic occurs in apps/internal/oauth/oauth.go at line 104:

if cred.TokenProvider != nil {

Here, cred is nil, leading to a runtime panic.

Fix

Added a conditional check to ensure that Token.Credential(...) is only called for confidential client flows (i.e., when silent.RequestType == accesstokens.ATConfidential), preventing the use of a nil credential for public clients.

Issue

#580

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 9, 2025

@4gust 4gust requested a review from chlowell September 25, 2025 10:35
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

@4gust 4gust merged commit f7579f7 into main Nov 4, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants