mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 18:57:35 +00:00
cmd/tsidp: add some docs
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
017a2ed349
commit
491b5fa92d
@ -83,17 +83,28 @@ type idpServer struct {
|
|||||||
lazySigner lazy.SyncValue[jose.Signer]
|
lazySigner lazy.SyncValue[jose.Signer]
|
||||||
|
|
||||||
mu sync.Mutex // guards the fields below
|
mu sync.Mutex // guards the fields below
|
||||||
|
|
||||||
code map[string]*authRequest
|
code map[string]*authRequest
|
||||||
accessToken map[string]*authRequest
|
accessToken map[string]*authRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
type authRequest struct {
|
type authRequest struct {
|
||||||
forNodeID string // string form nodeid:abcd
|
// requesterNodeID is the node who requested the auth (say synology), not the node
|
||||||
|
// who is being authenticated.
|
||||||
|
// String form of tailcfg.NodeID
|
||||||
|
requesterNodeID string
|
||||||
|
|
||||||
|
// nonce presented in the request.
|
||||||
nonce string
|
nonce string
|
||||||
|
|
||||||
|
// redirectURI is the redirect_uri presented in the request.
|
||||||
redirectURI string
|
redirectURI string
|
||||||
|
|
||||||
|
// remoteUser is the user who is being authenticated.
|
||||||
remoteUser *apitype.WhoIsResponse
|
remoteUser *apitype.WhoIsResponse
|
||||||
|
|
||||||
|
// validTill is the time until which the token is valid.
|
||||||
|
// As of 2023-11-14, it is 5 minutes.
|
||||||
|
// TODO: add routine to delete expired tokens.
|
||||||
validTill time.Time
|
validTill time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +130,7 @@ func (s *idpServer) authorize(w http.ResponseWriter, r *http.Request) {
|
|||||||
uq := r.URL.Query()
|
uq := r.URL.Query()
|
||||||
code := rands.HexString(32)
|
code := rands.HexString(32)
|
||||||
ar := &authRequest{
|
ar := &authRequest{
|
||||||
forNodeID: nodeID,
|
requesterNodeID: nodeID,
|
||||||
nonce: uq.Get("nonce"),
|
nonce: uq.Get("nonce"),
|
||||||
remoteUser: who,
|
remoteUser: who,
|
||||||
redirectURI: uq.Get("redirect_uri"),
|
redirectURI: uq.Get("redirect_uri"),
|
||||||
@ -173,7 +184,7 @@ func (s *idpServer) serveUserInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "tsidp: invalid token", http.StatusBadRequest)
|
http.Error(w, "tsidp: invalid token", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ar.forNodeID != who.Node.ID.String() {
|
if ar.requesterNodeID != who.Node.ID.String() {
|
||||||
http.Error(w, "tsidp: token for different node", http.StatusForbidden)
|
http.Error(w, "tsidp: token for different node", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -240,7 +251,7 @@ func (s *idpServer) serveToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "tsidp: code not found", http.StatusBadRequest)
|
http.Error(w, "tsidp: code not found", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ar.forNodeID != caller.Node.ID.String() {
|
if ar.requesterNodeID != caller.Node.ID.String() {
|
||||||
http.Error(w, "tsidp: token for different node", http.StatusForbidden)
|
http.Error(w, "tsidp: token for different node", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user