Skip to content

Commit

Permalink
refactor: rename session.sid to session.id
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The session field `sid` has been renamed to `id` to stay consistent with other APIs which also use `id` terminology to clarify identifiers. The payload of, for example, `/session/whoami` has changed as follows:

```patch
  {
-   "sid": "abcde",
+   "id": "abcde",
    "expires_at": "..."
    "identity": {
      // ..
    }
  }
```
  • Loading branch information
aeneasr committed Aug 25, 2020
1 parent 16c5618 commit 809fe73
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion continuity/manager_cookie.go
Expand Up @@ -97,7 +97,7 @@ func (m *ManagerCookie) sid(ctx context.Context, r *http.Request, name string) (
if s, err := x.SessionGetString(r, m.d.CookieManager(), cookieName, name); err != nil {
return sid, errors.WithStack(ErrNotResumable.WithDebugf("%+v", err))
} else if sid = x.ParseUUID(s); sid == uuid.Nil {
return sid, errors.WithStack(ErrNotResumable.WithDebug("sid is not a valid uuid"))
return sid, errors.WithStack(ErrNotResumable.WithDebug("session id is not a valid uuid"))
}

return sid, nil
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/oidc/strategy_test.go
Expand Up @@ -402,7 +402,7 @@ func TestStrategy(t *testing.T) {
require.NoError(t, reg.LoginFlowPersister().ForceLoginFlow(context.Background(), r2.ID))
res2, body2 := mrj(t, "valid", afv(t, r2.ID, "valid"), fv, jar)
ai(t, res2, body2)
assert.NotEqual(t, gjson.GetBytes(body1, "sid"), gjson.GetBytes(body2, "sid"))
assert.NotEqual(t, gjson.GetBytes(body1, "id"), gjson.GetBytes(body2, "id"))
authAt1, err := time.Parse(time.RFC3339, gjson.GetBytes(body1, "authenticated_at").String())
require.NoError(t, err)
authAt2, err := time.Parse(time.RFC3339, gjson.GetBytes(body2, "authenticated_at").String())
Expand Down
4 changes: 2 additions & 2 deletions selfservice/strategy/password/login_test.go
Expand Up @@ -640,7 +640,7 @@ func TestCompleteLogin(t *testing.T) {

require.Contains(t, res.Request.URL.Path, "return-ts", "%s", res.Request.URL.String())
assert.Equal(t, identifier, gjson.GetBytes(body2, "identity.traits.subject").String(), "%s", body2)
assert.NotEqual(t, gjson.GetBytes(body1, "sid").String(), gjson.GetBytes(body2, "sid").String(), "%s\n\n%s\n", body1, body2)
assert.NotEqual(t, gjson.GetBytes(body1, "id").String(), gjson.GetBytes(body2, "id").String(), "%s\n\n%s\n", body1, body2)
})

t.Run("should be the same session without forced flag", func(t *testing.T) {
Expand All @@ -660,6 +660,6 @@ func TestCompleteLogin(t *testing.T) {

require.Contains(t, res.Request.URL.Path, "return-ts", "%s", res.Request.URL.String())
assert.Equal(t, identifier, gjson.GetBytes(body2, "identity.traits.subject").String(), "%s", body2)
assert.Equal(t, gjson.GetBytes(body1, "sid").String(), gjson.GetBytes(body2, "sid").String(), "%s\n\n%s\n", body1, body2)
assert.Equal(t, gjson.GetBytes(body1, "id").String(), gjson.GetBytes(body2, "id").String(), "%s\n\n%s\n", body1, body2)
})
}
2 changes: 1 addition & 1 deletion selfservice/strategy/password/registration_test.go
Expand Up @@ -345,7 +345,7 @@ func TestRegistration(t *testing.T) {
assert.Contains(t, res.Request.URL.String(), publicTS.URL+password.RouteRegistration)
assert.Equal(t, `registration-identifier-8-api`, gjson.GetBytes(body, "identity.traits.username").String(), "%s", body)
assert.NotEmpty(t, gjson.GetBytes(body, "session_token").String(), "%s", body)
assert.NotEmpty(t, gjson.GetBytes(body, "session.sid").String(), "%s", body)
assert.NotEmpty(t, gjson.GetBytes(body, "session.id").String(), "%s", body)
})

t.Run("type=browser", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Expand Up @@ -14,7 +14,7 @@ import (
// swagger:model session
type Session struct {
// required: true
ID uuid.UUID `json:"sid" faker:"-" db:"id"`
ID uuid.UUID `json:"id" faker:"-" db:"id"`

Active bool `json:"active" db:"active"`

Expand Down

0 comments on commit 809fe73

Please sign in to comment.