mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 14:17:21 +01:00
Define and use an auth context structure
This commit is contained in:
parent
d917938a29
commit
3e464747d8
2 changed files with 19 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
|
@ -54,6 +55,12 @@ func (prov *IMAPProvider) doAuth(next http.Handler,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authCtx := AuthContext{
|
||||||
|
AuthMethod: "imap",
|
||||||
|
UserName: user,
|
||||||
|
}
|
||||||
|
ctx := context.WithValue(r.Context(), AuthCtxKey, &authCtx)
|
||||||
|
r = r.WithContext(ctx)
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,18 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var AuthCtxKey = &contextKey{"auth"}
|
||||||
|
|
||||||
|
type contextKey struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthContext struct {
|
||||||
|
AuthMethod string
|
||||||
|
UserName string
|
||||||
|
// TODO more?
|
||||||
|
}
|
||||||
|
|
||||||
// Abstracts the authentication backend for the server.
|
// Abstracts the authentication backend for the server.
|
||||||
type AuthProvider interface {
|
type AuthProvider interface {
|
||||||
// Returns HTTP middleware for performing authentication.
|
// Returns HTTP middleware for performing authentication.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue