Builds the OIDC callback based on the current request. Used during OIDC Client lazy initialization. Need to pass providerName and isDefault for the requested provider to determine whether we need to append it to the callback URL or not.
(providerName string, isDefault bool)
| 298 | // Builds the OIDC callback based on the current request. Used during OIDC Client lazy initialization. |
| 299 | // Need to pass providerName and isDefault for the requested provider to determine whether we need to append it to the callback URL or not. |
| 300 | func (h *handler) getOIDCCallbackURL(providerName string, isDefault bool) string { |
| 301 | // h.db not initialized at this point (checkPublicAuth) from validateAndWriteHeaders |
| 302 | // we'll have to pull it out of the router path rather than using h.db.Name |
| 303 | dbName := h.PathVar("db") |
| 304 | if dbName == "" { |
| 305 | // could be a keyspace-scoped request instead |
| 306 | dbName, _, _, _ = ParseKeyspace(h.PathVar("keyspace")) |
| 307 | } |
| 308 | |
| 309 | if dbName == "" { |
| 310 | base.WarnfCtx(h.ctx(), "Can't calculate OIDC callback URL without DB in path.") |
| 311 | return "" |
| 312 | } |
| 313 | |
| 314 | scheme := "http" |
| 315 | if h.rq.TLS != nil { |
| 316 | scheme = "https" |
| 317 | } |
| 318 | |
| 319 | callbackURL := scheme + "://" + h.rq.Host + "/" + dbName + "/_oidc_callback" |
| 320 | if isDefault || providerName == "" { |
| 321 | return callbackURL |
| 322 | } |
| 323 | |
| 324 | callbackURL, err := auth.SetURLQueryParam(callbackURL, auth.OIDCAuthProvider, providerName) |
| 325 | if err != nil { |
| 326 | base.WarnfCtx(h.ctx(), "Failed to add provider %q to OIDC callback URL (%s): %v", base.UD(providerName), callbackURL, err) |
| 327 | } |
| 328 | return callbackURL |
| 329 | } |
| 330 | |
| 331 | // makeStateCookie creates a new state cookie with the specified value and Max-Age. |
| 332 | // Max-Age has precedence whilst determining the state cookie expiration even though |
nothing calls this directly
no test coverage detected