GetClient initializes the client on first successful request.
(ctx context.Context, buildCallbackURLFunc OIDCCallbackURLFunc)
| 245 | |
| 246 | // GetClient initializes the client on first successful request. |
| 247 | func (op *OIDCProvider) GetClient(ctx context.Context, buildCallbackURLFunc OIDCCallbackURLFunc) (*OIDCClient, error) { |
| 248 | // If the callback URL isn't defined for the provider, uses buildCallbackURLFunc to construct (based on current request) |
| 249 | |
| 250 | if op.clientInit.IsTrue() { |
| 251 | return op.client, nil |
| 252 | } |
| 253 | op.clientInitLock.Lock() |
| 254 | defer op.clientInitLock.Unlock() |
| 255 | |
| 256 | // Check again to see if the previous lock holder initialized the client |
| 257 | if op.clientInit.IsTrue() { |
| 258 | return op.client, nil |
| 259 | } |
| 260 | |
| 261 | // If the redirect URL is not defined for the provider generate it from the |
| 262 | // handler request and set it on the provider |
| 263 | if op.CallbackURL == nil || *op.CallbackURL == "" { |
| 264 | callbackURL := buildCallbackURLFunc(op.Name, op.IsDefault) |
| 265 | if callbackURL != "" { |
| 266 | op.CallbackURL = &callbackURL |
| 267 | } |
| 268 | } |
| 269 | if err := op.initOIDCClient(ctx); err != nil { |
| 270 | return nil, err |
| 271 | } |
| 272 | op.clientInit.Set(true) |
| 273 | return op.client, nil |
| 274 | } |
| 275 | |
| 276 | // To support multiple providers referencing the same issuer, the user prefix used to build the SG usernames for |
| 277 | // a provider is based on the issuer |
no test coverage detected