diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 000000000..a7a720ebc --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,17 @@ +name: Format + +on: + pull_request: + push: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - run: make format + - name: Indicate formatting issues + run: git diff HEAD --exit-code --color diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..8716ccbcb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: Unit tests + +on: + pull_request: + push: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - run: make test diff --git a/.gitignore b/.gitignore index 0d39eabd0..25bca000d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.bin .idea *.iml .cover diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..1e816b997 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +.github/ISSUE_TEMPLATE/BUG-REPORT.yml +.github/ISSUE_TEMPLATE/DESIGN-DOC.yml +.github/ISSUE_TEMPLATE/FEATURE-REQUEST.yml +.github/ISSUE_TEMPLATE/config.yml +.github/pull_request_template.md +CHANGELOG.md +CONTRIBUTING.md diff --git a/.travis.yml b/.travis.yml index 6dd327af2..f6ec97b90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,9 @@ go: install: - go install github.com/mattn/goveralls - go install github.com/ory/go-acc - - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0 + - curl -sSfL + https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | + sh -s -- -b $(go env GOPATH)/bin v1.24.0 script: - golangci-lint run diff --git a/Makefile b/Makefile index 06218b8cd..13a99b0bf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,18 @@ -format: - goreturns -w -local github.com/ory $$(listx .) +format: .bin/goimports node_modules # formats the source code + .bin/goimports -w . + npm exec -- prettier --write . -test: - go test ./... +help: + @cat Makefile | grep '^[^ ]*:' | grep -v '^\.bin/' | grep -v '.SILENT:' | grep -v '^node_modules:' | grep -v help | sed 's/:.*#/#/' | column -s "#" -t +test: # runs all tests + go test ./... + +.bin/goimports: Makefile + GOBIN=$(shell pwd)/.bin go install golang.org/x/tools/cmd/goimports@latest + +node_modules: package-lock.json + npm ci + touch node_modules + +.DEFAULT_GOAL := help diff --git a/README.md b/README.md index 9d0ec6d4b..b0a0b2273 100644 --- a/README.md +++ b/README.md @@ -246,29 +246,35 @@ looking at some examples: ### Globalization -Fosite does not natively carry translations for error messages and hints, but offers an interface that allows the -consumer to define catalog bundles and an implementation to translate. This is available through -the [MessageCatalog](i18n/i18n.go) interface. The functions defined are self-explanatory. The `DefaultMessageCatalog` -illustrates this. Compose config has been extended to take in an instance of the `MessageCatalog`. +Fosite does not natively carry translations for error messages and hints, but +offers an interface that allows the consumer to define catalog bundles and an +implementation to translate. This is available through the +[MessageCatalog](i18n/i18n.go) interface. The functions defined are +self-explanatory. The `DefaultMessageCatalog` illustrates this. Compose config +has been extended to take in an instance of the `MessageCatalog`. #### Building translated files There are three possible "message key" types: -1. Value of `RFC6749Error.ErrorField`: This is a string like `invalid_request` and correlates to most errors produced by - Fosite. -2. Hint identifier passed into `RFC6749Error.WithHintIDOrDefaultf`: This func is not used extensively in Fosite but, in - time, most `WithHint` and `WithHintf` will be replaced with this function. -3. Free text string format passed into `RFC6749Error.WithHint` and `RFC6749Error.WithHintf`: This function is used in - Fosite and Hydra extensively and any message catalog implementation can use the format string parameter as the - message key. +1. Value of `RFC6749Error.ErrorField`: This is a string like `invalid_request` + and correlates to most errors produced by Fosite. +2. Hint identifier passed into `RFC6749Error.WithHintIDOrDefaultf`: This func is + not used extensively in Fosite but, in time, most `WithHint` and `WithHintf` + will be replaced with this function. +3. Free text string format passed into `RFC6749Error.WithHint` and + `RFC6749Error.WithHintf`: This function is used in Fosite and Hydra + extensively and any message catalog implementation can use the format string + parameter as the message key. -An example of a message catalog can be seen in the [i18n_test.go](i18n/i18n_test.go). +An example of a message catalog can be seen in the +[i18n_test.go](i18n/i18n_test.go). #### Generating the `en` messages file -This is a WIP at the moment, but effectively any scripting language can be used to generate this. It would need to -traverse all files in the source code and extract the possible message identifiers based on the different message key +This is a WIP at the moment, but effectively any scripting language can be used +to generate this. It would need to traverse all files in the source code and +extract the possible message identifiers based on the different message key types. ### Quickstart diff --git a/access_request_handler.go b/access_request_handler.go index 2bf79912d..ae46f0bf9 100644 --- a/access_request_handler.go +++ b/access_request_handler.go @@ -33,30 +33,30 @@ import ( ) // Implements -// * https://tools.ietf.org/html/rfc6749#section-2.3.1 -// Clients in possession of a client password MAY use the HTTP Basic -// authentication scheme as defined in [RFC2617] to authenticate with -// the authorization server. The client identifier is encoded using the -// "application/x-www-form-urlencoded" encoding algorithm per -// Appendix B, and the encoded value is used as the username; the client -// password is encoded using the same algorithm and used as the -// password. The authorization server MUST support the HTTP Basic -// authentication scheme for authenticating clients that were issued a -// client password. -// Including the client credentials in the request-body using the two -// parameters is NOT RECOMMENDED and SHOULD be limited to clients unable -// to directly utilize the HTTP Basic authentication scheme (or other -// password-based HTTP authentication schemes). The parameters can only -// be transmitted in the request-body and MUST NOT be included in the -// request URI. -// * https://tools.ietf.org/html/rfc6749#section-3.2.1 +// - https://tools.ietf.org/html/rfc6749#section-2.3.1 +// Clients in possession of a client password MAY use the HTTP Basic +// authentication scheme as defined in [RFC2617] to authenticate with +// the authorization server. The client identifier is encoded using the +// "application/x-www-form-urlencoded" encoding algorithm per +// Appendix B, and the encoded value is used as the username; the client +// password is encoded using the same algorithm and used as the +// password. The authorization server MUST support the HTTP Basic +// authentication scheme for authenticating clients that were issued a +// client password. +// Including the client credentials in the request-body using the two +// parameters is NOT RECOMMENDED and SHOULD be limited to clients unable +// to directly utilize the HTTP Basic authentication scheme (or other +// password-based HTTP authentication schemes). The parameters can only +// be transmitted in the request-body and MUST NOT be included in the +// request URI. +// - https://tools.ietf.org/html/rfc6749#section-3.2.1 // - Confidential clients or other clients issued client credentials MUST -// authenticate with the authorization server as described in -// Section 2.3 when making requests to the token endpoint. +// authenticate with the authorization server as described in +// Section 2.3 when making requests to the token endpoint. // - If the client type is confidential or the client was issued client -// credentials (or assigned other authentication requirements), the -// client MUST authenticate with the authorization server as described -// in Section 3.2.1. +// credentials (or assigned other authentication requirements), the +// client MUST authenticate with the authorization server as described +// in Section 3.2.1. func (f *Fosite) NewAccessRequest(ctx context.Context, r *http.Request, session Session) (AccessRequester, error) { accessRequest := NewAccessRequest(session) accessRequest.Request.Lang = i18n.GetLangFromRequest(f.Config.GetMessageCatalog(ctx), r) diff --git a/arguments.go b/arguments.go index 73783d657..8cbbfc103 100644 --- a/arguments.go +++ b/arguments.go @@ -28,8 +28,8 @@ type Arguments []string // Matches performs an case-insensitive, out-of-order check that the items // provided exist and equal all of the args in arguments. // Note: -// - Providing a list that includes duplicate string-case items will return not -// matched. +// - Providing a list that includes duplicate string-case items will return not +// matched. func (r Arguments) Matches(items ...string) bool { if len(r) != len(items) { return false diff --git a/authorize_error_test.go b/authorize_error_test.go index 753dae20c..3c5cf1d11 100644 --- a/authorize_error_test.go +++ b/authorize_error_test.go @@ -36,19 +36,19 @@ import ( ) // Test for -// * https://tools.ietf.org/html/rfc6749#section-4.1.2.1 -// If the request fails due to a missing, invalid, or mismatching -// redirection URI, or if the client identifier is missing or invalid, -// the authorization server SHOULD inform the resource owner of the -// error and MUST NOT automatically redirect the user-agent to the -// invalid redirection URI. -// * https://tools.ietf.org/html/rfc6749#section-3.1.2 -// The redirection endpoint URI MUST be an absolute URI as defined by -// [RFC3986] Section 4.3. The endpoint URI MAY include an -// "application/x-www-form-urlencoded" formatted (per Appendix B) query -// component ([RFC3986] Section 3.4), which MUST be retained when adding -// additional query parameters. The endpoint URI MUST NOT include a -// fragment component. +// - https://tools.ietf.org/html/rfc6749#section-4.1.2.1 +// If the request fails due to a missing, invalid, or mismatching +// redirection URI, or if the client identifier is missing or invalid, +// the authorization server SHOULD inform the resource owner of the +// error and MUST NOT automatically redirect the user-agent to the +// invalid redirection URI. +// - https://tools.ietf.org/html/rfc6749#section-3.1.2 +// The redirection endpoint URI MUST be an absolute URI as defined by +// [RFC3986] Section 4.3. The endpoint URI MAY include an +// "application/x-www-form-urlencoded" formatted (per Appendix B) query +// component ([RFC3986] Section 3.4), which MUST be retained when adding +// additional query parameters. The endpoint URI MUST NOT include a +// fragment component. func TestWriteAuthorizeError(t *testing.T) { var urls = []string{ "https://foobar.com/", diff --git a/authorize_helper.go b/authorize_helper.go index c5c064eed..29fd87d93 100644 --- a/authorize_helper.go +++ b/authorize_helper.go @@ -54,26 +54,27 @@ var DefaultFormPostTemplate = template.Must(template.New("form_post").Parse(`