Skip to content

Commit cb3bf1b

Browse files
committed
Removed some unnecessary boiler plate for some function
1 parent b7fe45f commit cb3bf1b

File tree

3 files changed

+12
-33
lines changed

3 files changed

+12
-33
lines changed

apps/internal/oauth/ops/accesstokens/accesstokens.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ func (c Client) FromClientSecret(ctx context.Context, authParameters authority.A
282282
addScopeQueryParam(qv, authParameters)
283283

284284
// Add extra body parameters if provided
285-
if err := addExtraBodyParameters(ctx, qv, authParameters); err != nil {
286-
return TokenResponse{}, err
287-
}
285+
addExtraBodyParameters(ctx, qv, authParameters)
288286

289287
return c.doTokenResp(ctx, authParameters, qv)
290288
}
@@ -302,9 +300,7 @@ func (c Client) FromAssertion(ctx context.Context, authParameters authority.Auth
302300
addScopeQueryParam(qv, authParameters)
303301

304302
// Add extra body parameters if provided
305-
if err := addExtraBodyParameters(ctx, qv, authParameters); err != nil {
306-
return TokenResponse{}, err
307-
}
303+
addExtraBodyParameters(ctx, qv, authParameters)
308304

309305
return c.doTokenResp(ctx, authParameters, qv)
310306
}
@@ -340,10 +336,7 @@ func (c Client) FromUserAssertionClientCertificate(ctx context.Context, authPara
340336
addScopeQueryParam(qv, authParameters)
341337

342338
// Add extra body parameters if provided
343-
if err := addExtraBodyParameters(ctx, qv, authParameters); err != nil {
344-
return TokenResponse{}, err
345-
}
346-
339+
addExtraBodyParameters(ctx, qv, authParameters)
347340
return c.doTokenResp(ctx, authParameters, qv)
348341
}
349342

@@ -483,15 +476,10 @@ func addScopeQueryParam(queryParams url.Values, authParameters authority.AuthPar
483476
}
484477

485478
// addExtraBodyParameters evaluates and adds extra body parameters to the request
486-
func addExtraBodyParameters(ctx context.Context, v url.Values, ap authority.AuthParams) error {
487-
if len(ap.ExtraBodyParameters) == 0 {
488-
return nil
489-
}
490-
479+
func addExtraBodyParameters(ctx context.Context, v url.Values, ap authority.AuthParams) {
491480
for key, value := range ap.ExtraBodyParameters {
492481
if value != "" {
493482
v.Set(key, value)
494483
}
495484
}
496-
return nil
497485
}

apps/internal/oauth/ops/accesstokens/extrabodyparams_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ func TestAddExtraBodyParameters(t *testing.T) {
9292
ap := authority.AuthParams{
9393
ExtraBodyParameters: tt.params,
9494
}
95-
err := addExtraBodyParameters(ctx, v, ap)
96-
if err != nil {
97-
t.Fatalf("unexpected error: %v", err)
98-
}
95+
addExtraBodyParameters(ctx, v, ap)
9996
if tt.validate != nil {
10097
tt.validate(t, v)
10198
}
@@ -116,10 +113,7 @@ func TestAddExtraBodyParametersDoesNotOverwrite(t *testing.T) {
116113
ExtraBodyParameters: params,
117114
}
118115

119-
err := addExtraBodyParameters(context.Background(), v, ap)
120-
if err != nil {
121-
t.Fatalf("unexpected error: %v", err)
122-
}
116+
addExtraBodyParameters(context.Background(), v, ap)
123117

124118
// Check that existing parameter is still there
125119
if v.Get("existing_param") != "existing_value" {

apps/internal/oauth/ops/authority/authority.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,20 +649,17 @@ func (a *AuthParams) AssertionHash() string {
649649
}
650650

651651
func (a *AuthParams) AppKey() string {
652-
baseKey := ""
652+
baseKey := a.ClientID + "_"
653653
if a.AuthorityInfo.Tenant != "" {
654-
baseKey = fmt.Sprintf("%s_%s", a.ClientID, a.AuthorityInfo.Tenant)
655-
} else {
656-
baseKey = fmt.Sprintf("%s_", a.ClientID)
654+
baseKey += a.AuthorityInfo.Tenant
657655
}
658656

659657
// Include extra body parameters in the cache key
660-
if len(a.CacheKeyComponents) > 0 {
661-
paramHash := a.CacheExtKeyGenerator()
662-
if paramHash != "" {
663-
baseKey = fmt.Sprintf("%s_%s", baseKey, paramHash)
664-
}
658+
paramHash := a.CacheExtKeyGenerator()
659+
if paramHash != "" {
660+
baseKey = fmt.Sprintf("%s_%s", baseKey, paramHash)
665661
}
662+
666663
return baseKey + "_AppTokenCache"
667664
}
668665

0 commit comments

Comments
 (0)