Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
45673cb
resolve conflicts
sebastien-rosset Oct 8, 2019
255a424
revert. set a preference for application/json content-type. Moved to …
sebastien-rosset Dec 6, 2019
23b895b
do not convert path to lowercase
sebastien-rosset Dec 7, 2019
25d6b31
add support for ecdsa keys
sebastien-rosset Dec 16, 2019
136f6b6
fix issue parsing ECDSA private key
sebastien-rosset Dec 17, 2019
91579d9
Sync from master
sebastien-rosset Jan 13, 2020
4ca55ce
remove unrelated python changes
sebastien-rosset Jan 13, 2020
0d6f013
Run go scripts under ./bin
sebastien-rosset Jan 13, 2020
d626293
Add support for HTTP signature
sebastien-rosset Jan 13, 2020
9eca52c
Add code comments
sebastien-rosset Jan 13, 2020
a59f759
Add code comments
sebastien-rosset Jan 13, 2020
9e6395f
add code comments
sebastien-rosset Jan 14, 2020
a6fd085
use bytes.Buffer instead of strings.Builder
sebastien-rosset Jan 14, 2020
70040b7
use bytes.Buffer instead of strings.Builder
sebastien-rosset Jan 14, 2020
2ccd0f9
Fix header of ECDSA private key
sebastien-rosset Jan 14, 2020
5131602
Add unit tests
sebastien-rosset Jan 14, 2020
af2e7a4
Add unit tests, compliance with HTTP signature draft version 12
sebastien-rosset Jan 14, 2020
d8175a0
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 14, 2020
cfd8d91
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 14, 2020
24944ca
improve code comments
sebastien-rosset Jan 14, 2020
cc564d3
Add unit tests, compliance with HTTP signature draft version 12
sebastien-rosset Jan 14, 2020
45ec612
Invoke bin scripts
sebastien-rosset Jan 14, 2020
ca87a61
compliance with HTTP signature draft 12
sebastien-rosset Jan 14, 2020
acfb44d
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 15, 2020
8a6039a
Support (expires) parameter. Add more unit tests and code comments
sebastien-rosset Jan 15, 2020
859ca30
Validate list of signed headers does not have duplicate values
sebastien-rosset Jan 15, 2020
bb12421
move method to ProcessUtils
sebastien-rosset Jan 15, 2020
7c1967e
Code reformatting
sebastien-rosset Jan 16, 2020
189f276
Add more validation for HTTP signature and more unit tests.
sebastien-rosset Jan 16, 2020
c8e9296
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 16, 2020
b895440
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 16, 2020
755335c
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 16, 2020
c9768d7
move http signature to separate file
sebastien-rosset Jan 16, 2020
3524696
Merge branch 'http-signature' of github.com:CiscoM31/openapi-generato…
sebastien-rosset Jan 16, 2020
4d45c08
move http signature to separate file
sebastien-rosset Jan 16, 2020
1bf286f
Add http-signature security scheme
sebastien-rosset Jan 17, 2020
6b4d774
Merge branch 'http-signature' of github.com:CiscoM31/openapi-generato…
sebastien-rosset Jan 17, 2020
5170195
Run sample scripts for go
sebastien-rosset Jan 17, 2020
ef59c0c
add http_signature_test to security scheme
sebastien-rosset Jan 17, 2020
0f7cbb1
Merge branch 'master' into http-signature
sebastien-rosset Jan 17, 2020
f8dea28
remove http signature from petapi
sebastien-rosset Jan 17, 2020
21e35f0
Add separate OAS file with support for HTTP signature
sebastien-rosset Jan 17, 2020
afb8cc6
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 17, 2020
5513fae
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 17, 2020
507c925
Use modules/openapi-generator/src/test/resources/3_0/petstore-with-fa…
sebastien-rosset Jan 17, 2020
daf060e
remove http signature from petstore-with-fake-endpoints-models-for-te…
sebastien-rosset Jan 17, 2020
f9ce3cb
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 17, 2020
efab4db
move http signature code to separate file
sebastien-rosset Jan 17, 2020
e8f7c49
move http signature code to separate file
sebastien-rosset Jan 18, 2020
bbbb5d6
move http signature code to separate file
sebastien-rosset Jan 18, 2020
986a26a
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 19, 2020
1b1aef6
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 19, 2020
b444929
Add passphrase to decrypt key
sebastien-rosset Jan 19, 2020
8168dd7
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 19, 2020
4f7e6eb
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 19, 2020
d5d2552
Add more unit tests
sebastien-rosset Jan 20, 2020
066237f
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 20, 2020
34f126f
do not throw exception if security scheme is unrecognized
sebastien-rosset Jan 20, 2020
46806f5
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 20, 2020
2374629
Include HTTP signature in README file
sebastien-rosset Jan 21, 2020
4f560aa
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 21, 2020
743aff2
Add generated files for HTTP signature
sebastien-rosset Jan 21, 2020
7b3a54b
change URL of apache license to use https
sebastien-rosset Jan 21, 2020
4ff092e
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 21, 2020
1f68d59
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 22, 2020
d8b0dc6
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 22, 2020
5dd76e8
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 22, 2020
f1f4973
http signature unit tests
sebastien-rosset Jan 23, 2020
88da56b
add more validation and unit tests
sebastien-rosset Jan 23, 2020
7d89594
Merge remote-tracking branch 'origin' into http-signature
sebastien-rosset Jan 23, 2020
6559f02
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 23, 2020
69970be
Merge branch 'http-signature' into golang-http-signature
sebastien-rosset Jan 23, 2020
816aebc
Add helper function to return public key, and add more unit tests for…
sebastien-rosset Jan 23, 2020
c7c7d42
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 24, 2020
b8be1bc
run sample scripts
sebastien-rosset Jan 24, 2020
17952bf
some people save their private key with file extensions other than .p…
sebastien-rosset Jan 24, 2020
6963f89
sync from master
sebastien-rosset Jan 26, 2020
9a83515
Merge remote-tracking branch 'origin' into golang-http-signature
sebastien-rosset Jan 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/openapi3/go-experimental-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ then
mvn -B clean package
fi

SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"
#SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml"
# petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml is the same as the above file, with
# the addition of the HTTP signature security scheme. Ideally, this would have been directly added to
# petstore-with-fake-endpoints-models-for-testing.yaml, but this cannot be done until issue #5025 is resolved.
SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml"
GENERATOR="go-experimental"
STUB_DIR="samples/openapi3/client/petstore/go-experimental/go-petstore"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.security.SecurityScheme;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenSecurity;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.utils.ProcessUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -67,6 +70,15 @@ public String getHelp() {
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("utils.mustache", "", "utils.go"));

// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
List<CodegenSecurity> authMethods = fromSecurity(securitySchemeMap);
if (ProcessUtils.hasHttpSignatureMethods(authMethods)) {
supportingFiles.add(new SupportingFile("signing.mustache", "", "signing.go"));
supportingFiles.add(new SupportingFile("http_signature_test.mustache", "", "http_signature_test.go"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ Class | Method | HTTP request | Description
Note, each API key must be added to a map of `map[string]APIKey` where the key is: {{keyParamName}} and passed in as the auth context for each request.

{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication

Example

Expand All @@ -116,6 +118,38 @@ auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAut
r, err := client.Service.Operation(auth, args)
```

{{/isBasicBasic}}
{{#isHttpSignature}}
- **Type**: HTTP signature authentication

Example

```golang
authConfig := sw.HttpSignatureAuth{
KeyId: "my-key-id",
PrivateKeyPath: "rsa.pem",
Passphrase: "my-passphrase",
SigningScheme: sw.HttpSigningSchemeHs2019,
SignedHeaders: []string{
sw.HttpSignatureParameterRequestTarget, // The special (request-target) parameter expresses the HTTP request target.
sw.HttpSignatureParameterCreated, // Time when request was signed, formatted as a Unix timestamp integer value.
"Host", // The Host request header specifies the domain name of the server, and optionally the TCP port number.
"Date", // The date and time at which the message was originated.
"Content-Type", // The Media type of the body of the request.
"Digest", // A cryptographic digest of the request body.
},
SigningAlgorithm: sw.HttpSigningAlgorithmRsaPSS,
SignatureMaxValidity: 5 * time.Minute,
}
var authCtx context.Context
var err error
if authCtx, err = authConfig.ContextWithValue(context.Background()); err != nil {
// Process error
}
r, err = client.Service.Operation(auth, args)

```
{{/isHttpSignature}}
{{/isBasic}}
{{#isOAuth}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,18 @@ func (c *APIClient) prepareRequest(
for header, value := range c.cfg.DefaultHeader {
localVarRequest.Header.Add(header, value)
}

{{#hasHttpSignatureMethods}}
if ctx != nil {
// HTTP Signature Authentication. All request headers must be set (including default headers)
// because the headers may be included in the signature.
if auth, ok := ctx.Value(ContextHttpSignatureAuth).(HttpSignatureAuth); ok {
err = SignRequest(ctx, localVarRequest, auth)
if err != nil {
return nil, err
}
}
}
{{/hasHttpSignatureMethods}}
return localVarRequest, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var (
// ContextAPIKeys takes a string apikey as authentication for the request
ContextAPIKeys = contextKey("apiKeys")

// ContextHttpSignatureAuth takes HttpSignatureAuth as authentication for the request.
ContextHttpSignatureAuth = contextKey("httpsignature")

// ContextServerIndex uses a server configuration from the index.
ContextServerIndex = contextKey("serverIndex")

Expand Down
Loading