-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip chore: resolve import cycle
- Loading branch information
Showing
8 changed files
with
89 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/gofrs/uuid" | ||
"github.com/teamhanko/hanko/backend/crypto/jwk" | ||
"github.com/teamhanko/hanko/backend/persistence" | ||
"github.com/teamhanko/hanko/backend/persistence/models" | ||
"github.com/teamhanko/hanko/backend/session" | ||
"github.com/teamhanko/hanko/backend/test" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func getDefaultSessionManager(storage persistence.Persister) session.Manager { | ||
jwkManager, _ := jwk.NewDefaultManager(test.DefaultConfig.Secrets.Keys, storage.GetJwkPersister()) | ||
sessionManager, _ := session.NewManager(jwkManager, test.DefaultConfig) | ||
return sessionManager | ||
} | ||
|
||
func generateSessionCookie(storage persistence.Persister, userId uuid.UUID) (*http.Cookie, error) { | ||
manager := getDefaultSessionManager(storage) | ||
token, rawToken, err := manager.GenerateJWT(userId, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
sessionID, _ := rawToken.Get("session_id") | ||
_ = storage.GetSessionPersister().Create(models.Session{ | ||
ID: uuid.FromStringOrNil(sessionID.(string)), | ||
UserID: userId, | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
ExpiresAt: nil, | ||
LastUsed: time.Now(), | ||
}) | ||
cookie, err := manager.GenerateCookie(token) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cookie, nil | ||
} |
Oops, something went wrong.