sessionSAMLNameID returns the full NameID of the request's session.
(r *http.Request)
| 44 | |
| 45 | // sessionSAMLNameID returns the full NameID of the request's session. |
| 46 | func (m *Middleware) sessionSAMLNameID(r *http.Request) (saml.NameID, error) { |
| 47 | session := SessionFromContext(r.Context()) |
| 48 | if session == nil { |
| 49 | if m.Session == nil { |
| 50 | return saml.NameID{}, ErrNoSession |
| 51 | } |
| 52 | var err error |
| 53 | session, err = m.Session.GetSession(r) |
| 54 | if err != nil { |
| 55 | return saml.NameID{}, err |
| 56 | } |
| 57 | if session == nil { |
| 58 | return saml.NameID{}, ErrNoSession |
| 59 | } |
| 60 | } |
| 61 | sessionWithNameID, ok := session.(SessionWithSAMLNameID) |
| 62 | if !ok { |
| 63 | return saml.NameID{}, fmt.Errorf("%w (session type %T does not implement SessionWithSAMLNameID)", |
| 64 | ErrSessionNameIDUnknown, session) |
| 65 | } |
| 66 | nameID, ok := sessionWithNameID.GetSAMLNameID() |
| 67 | if !ok { |
| 68 | return saml.NameID{}, fmt.Errorf("%w (the session predates the NameID Format claim)", ErrSessionNameIDUnknown) |
| 69 | } |
| 70 | return nameID, nil |
| 71 | } |
no test coverage detected