Skip to content

Commit

Permalink
Merge branch 'release/v0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhartstonge committed Jan 25, 2022
2 parents 2312892 + 3dc3dd8 commit 6006cf1
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 9 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: go
on: [ push, pull_request ]

jobs:
go:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 ]

steps:
- uses: actions/checkout@v2

- name: set up go@${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: go@${{ matrix.go }} build
run: go build -v ./...

- name: go@${{ matrix.go }} test
run: go test -v ./...
14 changes: 14 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: golangci-lint
on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run golangci-lint
uses: golangci/[email protected]
with:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest # optional
46 changes: 46 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
run:
timeout: 60s
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- errcheck
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- predeclared
- exportloopref
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- funlen
- gocyclo
- gochecknoinits
- gochecknoglobals
- lll
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [v0.1.1] - 2022-01-25
### Added
- :memo: README: adds code verifier verification examples.
- :page_facing_up: LICENSE: adds MIT license. Fixes #4.
- :construction_worker: ci/cd: enables github actions. Fixes #3.
- :memo: README: adds go reference, go report and github action build badges.

### Fixed
- :memo: README: fixes a couple of spelling misteaks.
- :rotating_light: pkce: fixes whitespace issues (wsl).
- :rotating_light: validation: simplifies if-return (revive).
- :rotating_light: errors: reduces line lengths (lll).

## [v0.1.0] - 2022-01-25
### Added
Expand All @@ -18,5 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Verification for an incoming code verifier.
- URL parameter key constants.

[Unreleased]: https://github.com/matthewhartstonge/pkce/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/matthewhartstonge/pkce/compare/v0.1.1...HEAD
[v0.1.1]: https://github.com/matthewhartstonge/pkce/releases/tag/v0.1.1
[v0.1.0]: https://github.com/matthewhartstonge/pkce/releases/tag/v0.1.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Matthew Hartstonge <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# pkce

[![Go Reference](https://pkg.go.dev/badge/github.com/matthewhartstonge/pkce.svg)](https://pkg.go.dev/github.com/matthewhartstonge/pkce)
[![Go Report Card](https://goreportcard.com/badge/github.com/matthewhartstonge/pkce)](https://goreportcard.com/report/github.com/matthewhartstonge/pkce)
[![Go Test](https://github.com/matthewhartstonge/pkce/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/matthewhartstonge/pkce/actions/workflows/go.yml)
[![golangci-lint](https://github.com/matthewhartstonge/pkce/actions/workflows/golangci-lint.yml/badge.svg?branch=main)](https://github.com/matthewhartstonge/pkce/actions/workflows/golangci-lint.yml)

`pkce` implements the client side of RFC 7636 "Proof Key for Code Exchange by OAuth Public Clients" (PKCE) to enable the
generation of cryptographically secure and specification compliant code verifiers and code challenges. With :sparkles:
no external dependencies :sparkles:.
Expand Down
11 changes: 9 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ var (

// ErrVerifierCharacters enforces character compliance with the unreserved
// character set as specified in RFC 7636, 4.1.
ErrVerifierCharacters = errors.New("code verifier must only contain unreserved characters in the set {'" + unreserved + "'}")
ErrVerifierCharacters = fmt.Errorf(
"code verifier must only contain unreserved characters from the set: {'%s'}",
unreserved,
)

// ErrVerifierLength enforces compliance with the minimum and maximum
// lengths as specified in RFC 7636, 4.1.
ErrVerifierLength = errors.New(fmt.Sprintf("code verifier must be between %d and %d characters long", verifierMinLen, verifierMaxLen))
ErrVerifierLength = fmt.Errorf(
"code verifier must be between %d and %d characters long",
verifierMinLen,
verifierMaxLen,
)
)
3 changes: 2 additions & 1 deletion pkce.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func VerifyCodeVerifier(method Method, codeVerifier string, codeChallenge string
// received "code_verifier" and comparing it with the previously associated
// "code_challenge", after first transforming it according to the
// "code_challenge_method" method specified by the client.

switch method {
case Plain:
// If the "code_challenge_method" from Section 4.3 was "plain", they are
Expand Down Expand Up @@ -172,6 +171,7 @@ func (k *Key) SetChallengeMethod(method Method) error {
}

k.challengeMethod = method

return nil
}

Expand All @@ -191,6 +191,7 @@ func (k *Key) setCodeVerifierLength(n int) error {
}

k.codeVerifierLen = n

return nil
}

Expand Down
6 changes: 1 addition & 5 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ func validateCodeVerifier(verifier []byte) error {
return err
}

if err := validateCodeVerifierCharacters(verifier); err != nil {
return err
}

return nil
return validateCodeVerifierCharacters(verifier)
}

// validateVerifierLen ensures the length of the code verifier is within the
Expand Down
3 changes: 3 additions & 0 deletions validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func Test_validateVerifierLen(t *testing.T) {
type args struct {
n int
}

tests := []struct {
name string
args args
Expand Down Expand Up @@ -43,6 +44,7 @@ func Test_validateVerifierLen(t *testing.T) {
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := validateVerifierLen(tt.args.n); (err != nil) != tt.wantErr {
Expand All @@ -56,6 +58,7 @@ func Test_validVerifierChar(t *testing.T) {
type args struct {
c byte
}

type validVerifierCharTest struct {
name string
args args
Expand Down

0 comments on commit 6006cf1

Please sign in to comment.