currentAccount returns the SAML NameID of the signed-in user, which identifies the owner of a link. It is taken from the session samlsp established, never from a request header a client could set itself.
(r *http.Request)
| 61 | // identifies the owner of a link. It is taken from the session samlsp |
| 62 | // established, never from a request header a client could set itself. |
| 63 | func currentAccount(r *http.Request) (string, bool) { |
| 64 | switch session := samlsp.SessionFromContext(r.Context()).(type) { |
| 65 | case samlsp.JWTSessionClaims: |
| 66 | // The default session codec stores the NameID value as the subject. |
| 67 | return session.Subject, session.Subject != "" |
| 68 | case samlsp.SessionWithSAMLNameID: |
| 69 | nameID, ok := session.GetSAMLNameID() |
| 70 | return nameID.Value, ok && nameID.Value != "" |
| 71 | default: |
| 72 | return "", false |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // newShortLink returns a random, URL-safe short link name. |
| 77 | func newShortLink() (string, error) { |
no test coverage detected