github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/client/mfa.go (about) 1 /* 2 Copyright 2023 Gravitational, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package client 18 19 import ( 20 "context" 21 22 "github.com/gravitational/trace" 23 24 "github.com/gravitational/teleport/api/client/proto" 25 "github.com/gravitational/teleport/api/mfa" 26 ) 27 28 // PerformMFACeremony retrieves an MFA challenge from the server with the given challenge extensions 29 // and prompts the user to answer the challenge with the given promptOpts, and ultimately returning 30 // an MFA challenge response for the user. 31 func (c *Client) PerformMFACeremony(ctx context.Context, challengeRequest *proto.CreateAuthenticateChallengeRequest, promptOpts ...mfa.PromptOpt) (*proto.MFAAuthenticateResponse, error) { 32 // Don't attempt the MFA ceremony if we can't prompt for a response. 33 if c.c.MFAPromptConstructor == nil { 34 return nil, trace.Wrap(&mfa.ErrMFANotSupported, "missing MFAPromptConstructor field, client cannot perform MFA ceremony") 35 } 36 37 return mfa.PerformMFACeremony(ctx, c, challengeRequest, promptOpts...) 38 } 39 40 // PromptMFA prompts the user for MFA. Implements [mfa.MFACeremonyClient]. 41 func (c *Client) PromptMFA(ctx context.Context, chal *proto.MFAAuthenticateChallenge, promptOpts ...mfa.PromptOpt) (*proto.MFAAuthenticateResponse, error) { 42 if c.c.MFAPromptConstructor == nil { 43 return nil, trace.Wrap(&mfa.ErrMFANotSupported, "missing MFAPromptConstructor field, client cannot prompt for MFA") 44 } 45 46 return c.c.MFAPromptConstructor(promptOpts...).Run(ctx, chal) 47 }