nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: zitadel/oidc
Pull request #337 (2023-03-17 16:13:20)

feat: GetUserinfo helper method for IDTokenClaims
https://github.com/zitadel/zitadel/pull/5437 can't build, because IDTokenClaims are no longer an interface matching with UserInfo in v2 of OIDC, on this line:

https://github.com/zitadel/zitadel/blob/f5d0378335ee969021de66ca05da46af020e53ec/internal/idp/providers/oidc/session.go#L50-L52

Instead, the UserInfo must be extracted from IDTokenClaims. This PR provides a Get method to make that process easier.


Patch:
diff --git a/pkg/oidc/token.go b/pkg/oidc/token.go
index b017023..127db97 100644
--- a/pkg/oidc/token.go
+++ b/pkg/oidc/token.go
@@ -159,6 +159,17 @@ func (t *IDTokenClaims) SetUserInfo(i *UserInfo) {
 	t.Address = i.Address
 }
 
+func (t *IDTokenClaims) GetUserInfo() *UserInfo {
+	return &UserInfo{
+		Subject:         t.Subject,
+		UserInfoProfile: t.UserInfoProfile,
+		UserInfoEmail:   t.UserInfoEmail,
+		UserInfoPhone:   t.UserInfoPhone,
+		Address:         t.Address,
+		Claims:          t.Claims,
+	}
+}
+
 func NewIDTokenClaims(issuer, subject string, audience []string, expiration, authTime time.Time, nonce string, acr string, amr []string, clientID string, skew time.Duration) *IDTokenClaims {
 	audience = AppendClientIDToAudience(clientID, audience)
 	return &IDTokenClaims{


Test patch:
diff --git a/pkg/oidc/token_test.go b/pkg/oidc/token_test.go
index 0d9874e..8dcfc7e 100644
--- a/pkg/oidc/token_test.go
+++ b/pkg/oidc/token_test.go
@@ -225,3 +225,16 @@ func TestNewIDTokenClaims(t *testing.T) {
 
 	assert.Equal(t, want, got)
 }
+
+func TestIDTokenClaims_GetUserInfo(t *testing.T) {
+	want := &UserInfo{
+		Subject:         idTokenData.Subject,
+		UserInfoProfile: idTokenData.UserInfoProfile,
+		UserInfoEmail:   idTokenData.UserInfoEmail,
+		UserInfoPhone:   idTokenData.UserInfoPhone,
+		Address:         idTokenData.Address,
+		Claims:          idTokenData.Claims,
+	}
+	got := idTokenData.GetUserInfo()
+	assert.Equal(t, want, got)
+}
Repository: zitadel/oidc
Pull request #339 (2023-03-20 13:18:10)

fix: handle the zero cases for oidc.Time
When Time fields was not set in JSON, the zero value `0`, resulted in a non-zero `time.Time` in conversion. This made verifier checks against a zero (unset) time always pass:

https://github.com/zitadel/oidc/blob/5a14f8d3e443d4e6a846451924bf993fcb8dd992/pkg/oidc/verifier.go#L179

This bug was most likely introduced in #283 refactorings.

Likewise, passing an empty time to `oidc.FromTime` now results in a `0` value for the JSON.


Patch:
diff --git a/pkg/oidc/types.go b/pkg/oidc/types.go
index cb513a0..167f8b7 100644
--- a/pkg/oidc/types.go
+++ b/pkg/oidc/types.go
@@ -173,10 +173,16 @@ func NewEncoder() *schema.Encoder {
 type Time int64
 
 func (ts Time) AsTime() time.Time {
+	if ts == 0 {
+		return time.Time{}
+	}
 	return time.Unix(int64(ts), 0)
 }
 
 func FromTime(tt time.Time) Time {
+	if tt.IsZero() {
+		return 0
+	}
 	return Time(tt.Unix())
 }
 


Test patch:
diff --git a/pkg/oidc/types_test.go b/pkg/oidc/types_test.go
index 2721e0b..64f07f1 100644
--- a/pkg/oidc/types_test.go
+++ b/pkg/oidc/types_test.go
@@ -7,6 +7,7 @@ import (
 	"strconv"
 	"strings"
 	"testing"
+	"time"
 
 	"github.com/gorilla/schema"
 	"github.com/stretchr/testify/assert"
@@ -467,6 +468,56 @@ func TestNewEncoder(t *testing.T) {
 	assert.Equal(t, a, b)
 }
 
+func TestTime_AsTime(t *testing.T) {
+	tests := []struct {
+		name string
+		ts   Time
+		want time.Time
+	}{
+		{
+			name: "unset",
+			ts:   0,
+			want: time.Time{},
+		},
+		{
+			name: "set",
+			ts:   1,
+			want: time.Unix(1, 0),
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got := tt.ts.AsTime()
+			assert.Equal(t, tt.want, got)
+		})
+	}
+}
+
+func TestTime_FromTime(t *testing.T) {
+	tests := []struct {
+		name string
+		tt   time.Time
+		want Time
+	}{
+		{
+			name: "zero",
+			tt:   time.Time{},
+			want: 0,
+		},
+		{
+			name: "set",
+			tt:   time.Unix(1, 0),
+			want: 1,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got := FromTime(tt.tt)
+			assert.Equal(t, tt.want, got)
+		})
+	}
+}
+
 func TestTime_UnmarshalJSON(t *testing.T) {
 	type dst struct {
 		UpdatedAt Time `json:"updated_at"`
Repository: zitadel/oidc
Pull request #637 (2024-08-17 13:39:12)

fix(op): initialize http Headers in response objects
When creating a new response or new redirect, the `http.Header` maps were left unitialized. This resulted in nil pointer panics when using methods such a `Set`.

This change initializes the `http.Header` maps in the `NewResponse` and `NewRedirect` functions.

Related to https://github.com/zitadel/zitadel/issues/8031 which requires setting of response headers.

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [x] All open todos and follow ups are defined in a new ticket and justified
- [x] Deviations from the acceptance criteria and design are agreed with the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [x] Critical parts are tested automatically
- [x] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [x] All non-functional requirements are met
- [x] Functionality of the acceptance criteria is checked manually on the dev system.




Patch:
diff --git a/pkg/op/server.go b/pkg/op/server.go
index 6faee87..b500e43 100644
--- a/pkg/op/server.go
+++ b/pkg/op/server.go
@@ -218,7 +218,8 @@ type Response struct {
 // without custom headers.
 func NewResponse(data any) *Response {
 	return &Response{
-		Data: data,
+		Header: make(http.Header),
+		Data:   data,
 	}
 }
 
@@ -242,7 +243,10 @@ type Redirect struct {
 }
 
 func NewRedirect(url string) *Redirect {
-	return &Redirect{URL: url}
+	return &Redirect{
+		Header: make(http.Header),
+		URL:    url,
+	}
 }
 
 func (red *Redirect) writeOut(w http.ResponseWriter, r *http.Request) {


Test patch:
diff --git a/pkg/op/error_test.go b/pkg/op/error_test.go
index 170039c..107f9d0 100644
--- a/pkg/op/error_test.go
+++ b/pkg/op/error_test.go
@@ -428,7 +428,8 @@ func TestTryErrorRedirect(t *testing.T) {
 				parent: oidc.ErrInteractionRequired().WithDescription("sign in"),
 			},
 			want: &Redirect{
-				URL: "http://example.com/callback?error=interaction_required&error_description=sign+in&state=state1",
+				Header: make(http.Header),
+				URL:    "http://example.com/callback?error=interaction_required&error_description=sign+in&state=state1",
 			},
 			wantLog: `{
 						"level":"WARN",