fix http bear auth documentation for go clinets (#7312)

This commit is contained in:
QP Hou
2020-08-30 22:43:34 -07:00
committed by GitHub
parent d5a680e85f
commit 30074833cd
6 changed files with 59 additions and 38 deletions

View File

@@ -105,6 +105,17 @@ Note, each API key must be added to a map of `map[string]APIKey` where the key i
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBearer}}
- **Type**: HTTP Bearer token authentication
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
{{/isBasicBearer}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication

View File

@@ -64,7 +64,7 @@ Class | Method | HTTP request | Description
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), {{packageName}}.ContextAPIKey, {{packageName}}.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -72,19 +72,33 @@ r, err := client.Service.Operation(auth, args)
```
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isHttpSignature}}
Not supported.
{{/isHttpSignature}}
{{#isBasicBasic}}- **Type**: HTTP basic authentication
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), {{packageName}}.ContextBasicAuth, {{packageName}}.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
{{/isBasic}}
{{/isBasicBasic}}
{{#isBasicBearer}}- **Type**: HTTP Bearer token authentication
Example
```golang
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
{{/isBasicBearer}}
{{#isOAuth}}
- **Type**: OAuth
@@ -97,7 +111,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
@@ -109,7 +123,7 @@ import "golang.org/x/oauth2"
/* Perform OAuth2 round trip request and obtain a token */
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
auth := context.WithValue(oauth2.NoContext, {{packageName}}.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```
@@ -120,7 +134,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAWSv4, sw.AWSv4{
auth := context.WithValue(context.Background(), {{packageName}}.ContextAWSv4, {{packageName}}.AWSv4{
AccessKey: "ACCESSKEYSTRING",
SecretKey: "SECRETKEYSTRING",
})

View File

@@ -134,7 +134,7 @@ Class | Method | HTTP request | Description
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -149,7 +149,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -164,7 +164,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
@@ -185,7 +185,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
@@ -197,7 +197,7 @@ import "golang.org/x/oauth2"
/* Perform OAuth2 round trip request and obtain a token */
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

View File

@@ -134,7 +134,7 @@ Class | Method | HTTP request | Description
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -149,7 +149,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -164,7 +164,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
@@ -185,7 +185,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
@@ -197,7 +197,7 @@ import "golang.org/x/oauth2"
/* Perform OAuth2 round trip request and obtain a token */
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

View File

@@ -199,6 +199,15 @@ Note, each API key must be added to a map of `map[string]APIKey` where the key i
### bearer_test
- **Type**: HTTP Bearer token authentication
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
### http_basic_test

View File

@@ -137,7 +137,7 @@ Class | Method | HTTP request | Description
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -152,7 +152,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
@@ -162,15 +162,12 @@ r, err := client.Service.Operation(auth, args)
## bearer_test
- **Type**: HTTP basic authentication
- **Type**: HTTP Bearer token authentication
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
@@ -182,7 +179,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
@@ -192,17 +189,7 @@ r, err := client.Service.Operation(auth, args)
## http_signature_test
- **Type**: HTTP basic authentication
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
Not supported.
## petstore_auth
@@ -218,7 +205,7 @@ r, err := client.Service.Operation(auth, args)
Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```
@@ -230,7 +217,7 @@ import "golang.org/x/oauth2"
/* Perform OAuth2 round trip request and obtain a token */
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```