github.com/Jeffail/benthos/v3@v3.65.0/lib/util/http/auth/docs.go (about)

     1  package auth
     2  
     3  import "github.com/Jeffail/benthos/v3/internal/docs"
     4  
     5  // BasicAuthFieldSpec returns a basic authentication field spec.
     6  func BasicAuthFieldSpec() docs.FieldSpec {
     7  	return docs.FieldAdvanced("basic_auth",
     8  		"Allows you to specify basic authentication.",
     9  	).WithChildren(
    10  		docs.FieldCommon(
    11  			"enabled", "Whether to use basic authentication in requests.",
    12  		).HasType(docs.FieldTypeBool).HasDefault(false),
    13  
    14  		docs.FieldString("username", "A username to authenticate as.").HasDefault(""),
    15  		docs.FieldString("password", "A password to authenticate with.").HasDefault(""),
    16  	)
    17  }
    18  
    19  func oAuthFieldSpec() docs.FieldSpec {
    20  	return docs.FieldAdvanced("oauth",
    21  		"Allows you to specify open authentication via OAuth version 1.",
    22  	).WithChildren(
    23  		docs.FieldCommon(
    24  			"enabled", "Whether to use OAuth version 1 in requests.",
    25  		).HasType(docs.FieldTypeBool).HasDefault(false),
    26  
    27  		docs.FieldString(
    28  			"consumer_key", "A value used to identify the client to the service provider.",
    29  		).HasDefault(""),
    30  
    31  		docs.FieldString(
    32  			"consumer_secret", "A secret used to establish ownership of the consumer key.",
    33  		).HasDefault(""),
    34  
    35  		docs.FieldString(
    36  			"access_token", "A value used to gain access to the protected resources on behalf of the user.",
    37  		).HasDefault(""),
    38  
    39  		docs.FieldString(
    40  			"access_token_secret", "A secret provided in order to establish ownership of a given access token.",
    41  		).HasDefault(""),
    42  
    43  		docs.FieldString(
    44  			"request_url", "The URL of the OAuth provider.",
    45  		).HasDefault(""),
    46  	)
    47  }
    48  
    49  func oAuth2FieldSpec() docs.FieldSpec {
    50  	return docs.FieldAdvanced("oauth2",
    51  		"Allows you to specify open authentication via OAuth version 2 using the client credentials token flow.",
    52  	).WithChildren(
    53  		docs.FieldCommon(
    54  			"enabled", "Whether to use OAuth version 2 in requests.",
    55  		).HasType(docs.FieldTypeBool).HasDefault(false),
    56  
    57  		docs.FieldString(
    58  			"client_key", "A value used to identify the client to the token provider.",
    59  		).HasDefault(""),
    60  
    61  		docs.FieldString(
    62  			"client_secret", "A secret used to establish ownership of the client key.",
    63  		).HasDefault(""),
    64  
    65  		docs.FieldString(
    66  			"token_url", "The URL of the token provider.",
    67  		).HasDefault(""),
    68  
    69  		docs.FieldAdvanced(
    70  			"scopes", "A list of optional requested permissions.",
    71  		).Array().AtVersion("3.45.0").HasType(docs.FieldTypeString),
    72  	)
    73  }
    74  
    75  func jwtFieldSpec() docs.FieldSpec {
    76  	return docs.FieldAdvanced("jwt",
    77  		"BETA: Allows you to specify JWT authentication.",
    78  	).WithChildren(
    79  		docs.FieldCommon(
    80  			"enabled", "Whether to use JWT authentication in requests.",
    81  		).HasType(docs.FieldTypeBool).HasDefault(false),
    82  
    83  		docs.FieldString(
    84  			"private_key_file", "A file with the PEM encoded via PKCS1 or PKCS8 as private key.",
    85  		).HasDefault(""),
    86  
    87  		docs.FieldString(
    88  			"signing_method", "A method used to sign the token such as RS256, RS384 or RS512.",
    89  		).HasDefault(""),
    90  
    91  		docs.FieldAdvanced(
    92  			"claims", "A value used to identify the claims that issued the JWT.",
    93  		).Map().HasType(docs.FieldTypeUnknown),
    94  	)
    95  }
    96  
    97  // FieldSpecs returns a map of field specs for an auth type.
    98  func FieldSpecs() docs.FieldSpecs {
    99  	return docs.FieldSpecs{
   100  		oAuthFieldSpec(),
   101  		BasicAuthFieldSpec(),
   102  		jwtFieldSpec(),
   103  	}
   104  }
   105  
   106  // FieldSpecsExpanded includes OAuth2 and JWT fields that might not be appropriate for all components.
   107  func FieldSpecsExpanded() docs.FieldSpecs {
   108  	return docs.FieldSpecs{
   109  		oAuthFieldSpec(),
   110  		oAuth2FieldSpec(),
   111  		jwtFieldSpec(),
   112  		BasicAuthFieldSpec(),
   113  	}
   114  }