@@ -142,7 +142,7 @@ func New(clientID string, options ...Option) (Client, error) {
142142
143143// authCodeURLOptions contains options for AuthCodeURL
144144type authCodeURLOptions struct {
145- claims , loginHint , tenantID , domainHint string
145+ claims , loginHint , tenantID , domainHint , state string
146146}
147147
148148// AuthCodeURLOption is implemented by options for AuthCodeURL
@@ -152,7 +152,7 @@ type AuthCodeURLOption interface {
152152
153153// AuthCodeURL creates a URL used to acquire an authorization code.
154154//
155- // Options: [WithClaims], [WithDomainHint], [WithLoginHint], [WithTenantID]
155+ // Options: [WithClaims], [WithDomainHint], [WithLoginHint], [WithTenantID], [WithState]
156156func (pca Client ) AuthCodeURL (ctx context.Context , clientID , redirectURI string , scopes []string , opts ... AuthCodeURLOption ) (string , error ) {
157157 o := authCodeURLOptions {}
158158 if err := options .ApplyOptions (& o , opts ); err != nil {
@@ -162,12 +162,36 @@ func (pca Client) AuthCodeURL(ctx context.Context, clientID, redirectURI string,
162162 if err != nil {
163163 return "" , err
164164 }
165+ ap .State = o .state
165166 ap .Claims = o .claims
166167 ap .LoginHint = o .loginHint
167168 ap .DomainHint = o .domainHint
168169 return pca .base .AuthCodeURL (ctx , clientID , redirectURI , scopes , ap )
169170}
170171
172+ // WithState adds a user-generated state to the request.
173+ func WithState (state string ) interface {
174+ AuthCodeURLOption
175+ options.CallOption
176+ } {
177+ return struct {
178+ AuthCodeURLOption
179+ options.CallOption
180+ }{
181+ CallOption : options .NewCallOption (
182+ func (a any ) error {
183+ switch t := a .(type ) {
184+ case * authCodeURLOptions :
185+ t .state = state
186+ default :
187+ return fmt .Errorf ("unexpected options type %T" , a )
188+ }
189+ return nil
190+ },
191+ ),
192+ }
193+ }
194+
171195// WithClaims sets additional claims to request for the token, such as those required by conditional access policies.
172196// Use this option when Azure AD returned a claims challenge for a prior request. The argument must be decoded.
173197// This option is valid for any token acquisition method.
@@ -519,9 +543,9 @@ func (pca Client) RemoveAccount(ctx context.Context, account Account) error {
519543
520544// interactiveAuthOptions contains the optional parameters used to acquire an access token for interactive auth code flow.
521545type interactiveAuthOptions struct {
522- claims , domainHint , loginHint , redirectURI , tenantID string
523- openURL func (url string ) error
524- authnScheme AuthenticationScheme
546+ claims , domainHint , loginHint , redirectURI , tenantID , state string
547+ openURL func (url string ) error
548+ authnScheme AuthenticationScheme
525549}
526550
527551// AcquireInteractiveOption is implemented by options for AcquireTokenInteractive
0 commit comments