Compare commits
No commits in common. "d1c5bde5c1c44125d0e6dd3b211203075ef0af9e" and "040c662826a0b08f86e3ea1ef2311e302e5ffb9e" have entirely different histories.
d1c5bde5c1
...
040c662826
|
@ -287,11 +287,9 @@ func (a AccountAPI) passwordResetConfirm(jc jape.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AccountAPI) ping(jc jape.Context) {
|
func (a AccountAPI) ping(jc jape.Context) {
|
||||||
token := middleware.GetAuthTokenFromContext(jc.Request.Context())
|
|
||||||
account.EchoAuthCookie(jc, a.Name())
|
account.EchoAuthCookie(jc, a.Name())
|
||||||
jc.Encode(&PongResponse{
|
jc.Encode(&PongResponse{
|
||||||
Ping: "pong",
|
Ping: "pong",
|
||||||
Token: token,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ type PasswordResetVerifyRequest struct {
|
||||||
|
|
||||||
type PongResponse struct {
|
type PongResponse struct {
|
||||||
Ping string `json:"ping"`
|
Ping string `json:"ping"`
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
}
|
||||||
type AccountInfoResponse struct {
|
type AccountInfoResponse struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
|
|
|
@ -253,8 +253,6 @@ components:
|
||||||
properties:
|
properties:
|
||||||
ping:
|
ping:
|
||||||
type: string
|
type: string
|
||||||
token:
|
|
||||||
type: string
|
|
||||||
AccountInfoResponse:
|
AccountInfoResponse:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_AUTH_CONTEXT_KEY = "user_id"
|
const DEFAULT_AUTH_CONTEXT_KEY = "user_id"
|
||||||
const AUTH_TOKEN_CONTEXT_KEY = "auth_token"
|
|
||||||
|
|
||||||
type JapeMiddlewareFunc func(jape.Handler) jape.Handler
|
type JapeMiddlewareFunc func(jape.Handler) jape.Handler
|
||||||
type HttpMiddlewareFunc func(http.Handler) http.Handler
|
type HttpMiddlewareFunc func(http.Handler) http.Handler
|
||||||
|
@ -155,7 +154,6 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), options.AuthContextKey, uint(userId))
|
ctx := context.WithValue(r.Context(), options.AuthContextKey, uint(userId))
|
||||||
ctx = context.WithValue(r.Context(), AUTH_TOKEN_CONTEXT_KEY, authToken)
|
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
@ -194,17 +192,6 @@ func GetUserFromContext(ctx context.Context, key ...string) uint {
|
||||||
|
|
||||||
return userId
|
return userId
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAuthTokenFromContext(ctx context.Context) string {
|
|
||||||
authToken, ok := ctx.Value(AUTH_TOKEN_CONTEXT_KEY).(string)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
panic("auth token stored in context is not of type string")
|
|
||||||
}
|
|
||||||
|
|
||||||
return authToken
|
|
||||||
}
|
|
||||||
|
|
||||||
func CtxAborted(ctx context.Context) bool {
|
func CtxAborted(ctx context.Context) bool {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
Loading…
Reference in New Issue