src/server/auth/server/api_server.go
func (a *apiServer) getOneTimePassword(ctx context.Context, username string, expiration time.Time) (code string, err error) {
	// Create OTPInfo that will be stored
	otpInfo := &authclient.OTPInfo{
		Subject: username,
	}
	if !expiration.IsZero() {
		expirationProto, err := types.TimestampProto(expiration)
		if err != nil {
			return "", fmt.Errorf("could not create OTP with expiration time %s: %v",
				expiration.String(), err)
		}
		otpInfo.SessionExpiration = expirationProto
	}

	// Generate and store new OTP
	code = "auth_code:" + uuid.NewWithoutDashes()
	if _, err = col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
		return a.authenticationCodes.ReadWrite(stm).PutTTL(hashToken(code),
			otpInfo, defaultAuthCodeTTLSecs)
	}); err != nil {
		return "", err
	}
	return code, nil
}
func (a *apiServer) getOneTimePassword(ctx context.Context, username string, expiration time.Time) (code string, err error) {
	// Create OTPInfo that will be stored
	otpInfo := &authclient.OTPInfo{
		Subject: username,
	}
	if !expiration.IsZero() {
		expirationProto, err := types.TimestampProto(expiration)
		if err != nil {
			return "", fmt.Errorf("could not create OTP with expiration time %s: %v",
				expiration.String(), err)
		}
		otpInfo.SessionExpiration = expirationProto
	}

	// Generate and store new OTP
	code = "auth_code:" + uuid.NewWithoutDashes()
	if _, err = col.NewSTM(ctx, a.env.GetEtcdClient(), func(stm col.STM) error {
		return a.authenticationCodes.ReadWrite(stm).PutTTL(hashToken(code),
			otpInfo, defaultAuthCodeTTLSecs)
	}); err != nil {
		return "", err
	}
	return code, nil
}
func ( a * apiServer ) getOneTimePassword ( ctx context . Context , username string , expiration time . Time ) ( code string , err error ) { // Create OTPInfo that will be stored otpInfo := & authclient . OTPInfo { Subject : username , } if ! expiration . IsZero ( ) { expirationProto , err := types . TimestampProto ( expiration ) if err != nil { return " " , fmt . Errorf ( " " , expiration . String ( ) , err ) } otpInfo . SessionExpiration = expirationProto } // Generate and store new OTP code = " " + uuid . NewWithoutDashes ( ) if _ , err = col . NewSTM ( ctx , a . env . GetEtcdClient ( ) , func ( stm col . STM ) error { return a . authenticationCodes . ReadWrite ( stm ) . PutTTL ( hashToken ( code ) , otpInfo , defaultAuthCodeTTLSecs ) } ) ; err != nil { return " " , err } return code , nil }
// getOneTimePassword contains the implementation of GetOneTimePassword,
// but is also called directly by handleSAMLREsponse. It generates a
// short-lived authentication code for 'username', writes it to
// a.authenticationCodes, and returns it
getOneTimePassword contains the implementation of GetOneTimePassword but is also called directly by handleSAMLREsponse . It generates a short - lived authentication code for username writes it to a . authenticationCodes and returns it