Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-device-credentials-support
Browse files Browse the repository at this point in the history
developerkunal authored May 3, 2024
2 parents 031e4c4 + 769e738 commit bf6756d
Showing 104 changed files with 2,857 additions and 1,501 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -28,8 +28,9 @@ jobs:
AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }}

- name: Update codecov report
uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # [email protected].5
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
fail_ci_if_error: false
verbose: true
verbose: true
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ jobs:
run: go build ./...

- name: Check for linting errors
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # pin@4.0.0
uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # pin@5.1.0
with:
version: latest
args: -v -c .golangci.yml
@@ -48,8 +48,9 @@ jobs:
run: make test

- name: Update codecov report
uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # [email protected].5
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
fail_ci_if_error: false
verbose: true
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.1
v1.5.0
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [v1.5.0](https://github.com/auth0/go-auth0/tree/v1.5.0) (2024-04-23)
[Full Changelog](https://github.com/auth0/go-auth0/compare/v1.4.1...v1.5.0)

**Added**
- Send extra parameters with client credentials request [\#354](https://github.com/auth0/go-auth0/pull/354) ([weirdian2k3](https://github.com/weirdian2k3))
- Add support for `oidc_logout` parameters [\#384](https://github.com/auth0/go-auth0/pull/384) ([developerkunal](https://github.com/developerkunal))
- Add `show_as_button` field to Organization Enabled Connection [\#386](https://github.com/auth0/go-auth0/pull/386) ([developerkunal](https://github.com/developerkunal))

**Fixed**
- Fix sending unnecessary `null` body in requests [\#387](https://github.com/auth0/go-auth0/pull/387) ([developerkunal](https://github.com/developerkunal))

## [v1.4.1](https://github.com/auth0/go-auth0/tree/v1.4.1) (2024-02-28)
[Full Changelog](https://github.com/auth0/go-auth0/compare/v1.4.0...v1.4.1)

53 changes: 51 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,23 @@
We appreciate feedback and contribution to this repo.
Before you submit a pull request, there are a couple requirements to satisfy.

## Prerequisites

Ensure you have the following prerequisites met:

- **Go Version**: You must have Go version 1.21 or newer installed on your system. You can check your Go version by running `go version` in your terminal.
- **GOPATH Set Up**: Make sure you have set up your GOPATH.
- **Export GOPATH**: Ensure you have exported your GOPATH to your system's environment variables. This allows tools and libraries to locate your Go workspace.
- **Modify bashrc or zshrc**: To automatically set your GOPATH and export it every time you open a terminal, you can add the following lines to your `~/.bashrc` or `~/.zshrc` file on Linux and macOS systems:
- **Enviroment File**: Ensure you have a `.env` file in the root folder of the repository or that the environment variables have been exported.

```sh
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
```

After adding these lines, run source `~/.bashrc` or source `~/.zshrc` to apply the changes.

## Generating the Getters

The SDK offers safe getters in order to access pointer fields to avoid panics on nil pointers.
@@ -20,6 +37,38 @@ fmt.Printf("Logo URI: %v", client.GetLogoURI())

When adding a new pointer field to a struct, run `make generate` to generate the getter for it.

## Code Quality and Security

### Linting

Before submitting your pull request, ensure your code follows the project's coding standards by running the linting task:

```sh
make lint
```

This will run golangci-lint across the codebase, identifying potential stylistic issues and suspicious constructs.

### Vulnerability Checking

To check for any known vulnerabilities in the dependencies, run:

```sh
make check-vuln
```

This uses govulncheck to scan the codebase for known security issues in the Go ecosystem.

### Generating Accessors and Testing for Getters

Ensure that your changes include any necessary updates to the accessor methods and that all struct field getters are correctly generated by running:

```sh
make check-getters
```

This command will verify that all getters are up to date and generate any missing ones.

## Running the Tests

There are two ways of running the tests:
@@ -32,7 +81,7 @@ There are two ways of running the tests:
To run the tests against an Auth0 tenant start by creating an M2M app using `auth0 apps create --name go-auth0-mgmt-tests --description "App used for go-auth0 management tests" --type m2m`, then
run `auth0 apps open <CLIENT ID>`. Authorize the Management API in the `APIs` tab and enable all permissions.

Then create a local `.env` file in the `management` folder with the following settings:
Then create a `.env` file in the root folder of the repository with the following details :

* `AUTH0_DOMAIN`: The **Domain** of the Auth0 tenant
* `AUTH0_CLIENT_ID`: The **Client ID** of the M2M app
@@ -43,7 +92,7 @@ Then create a local `.env` file in the `management` folder with the following se
Now for the Authentication tests create another M2M app using `auth0 apps create --name go-auth0-auth-tests --description "App used for go-auth0 authentication tests" --type m2m`, then run
`auth0 apps open <CLIENT ID>`. Ensure all `Grant Types` except `Client Credentials` are enabled in `Advanced Settings`, then set the `Authentication Method` to `None` in the `Credentials` tab.

Then create a local `.env` file in the `authentication` folder with the following settings:
Then create a `.env` file in the root folder of the repository with the following details :

* `AUTH0_DOMAIN`: The **Domain** of the Auth0 tenant
* `AUTH0_CLIENT_ID`: The **Client ID** of the management M2M app
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ $(GO_BIN)/golangci-lint:
@go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest

$(GO_BIN)/govulncheck:
${call print, "Installing govulncheck"}
@go install -v golang.org/x/vuln/cmd/govulncheck@latest

#-----------------------------------------------------------------------------------------------------------------------
16 changes: 11 additions & 5 deletions authentication/authentication_error.go
Original file line number Diff line number Diff line change
@@ -54,11 +54,11 @@ func (a *Error) UnmarshalJSON(b []byte) error {
type authError Error
type authErrorWrapper struct {
*authError
Code string `json:"code"`
Description string `json:"description"`
Code string `json:"code"`
Description json.RawMessage `json:"description"` // Can be string or object
}

alias := &authErrorWrapper{(*authError)(a), "", ""}
alias := &authErrorWrapper{(*authError)(a), "", nil}

err := json.Unmarshal(b, alias)
if err != nil {
@@ -69,8 +69,14 @@ func (a *Error) UnmarshalJSON(b []byte) error {
a.Err = alias.Code
}

if alias.Description != "" {
a.Message = alias.Description
if len(alias.Description) > 0 {
var descText string
err := json.Unmarshal(alias.Description, &descText)
if err == nil {
a.Message = descText
} else {
a.Message = string(alias.Description)
}
}

return nil
12 changes: 12 additions & 0 deletions authentication/authentication_error_test.go
Original file line number Diff line number Diff line change
@@ -63,6 +63,18 @@ func Test_newError(t *testing.T) {
Message: "Invalid sign up",
},
},
{
name: "it will handle invalid password response",
givenResponse: http.Response{
StatusCode: http.StatusBadRequest,
Body: io.NopCloser((strings.NewReader(`{"name":"PasswordStrengthError","message":"Password is too weak","code":"invalid_password","description":{"rules":[{"message":"At least %d characters in length","format":[8],"code":"lengthAtLeast","verified":true},{"message":"Contain at least %d of the following %d types of characters:","code":"containsAtLeast","format":[3,4],"items":[{"message":"lower case letters (a-z)","code":"lowerCase","verified":true},{"message":"upper case letters (A-Z)","code":"upperCase","verified":false},{"message":"numbers (i.e. 0-9)","code":"numbers","verified":false},{"message":"special characters (e.g. !@#$%^&*)","code":"specialCharacters","verified":true}],"verified":false}],"verified":false},"policy":"* At least 8 characters in length\n* Contain at least 3 of the following 4 types of characters:\n * lower case letters (a-z)\n * upper case letters (A-Z)\n * numbers (i.e. 0-9)\n * special characters (e.g. !@#$%^&*)","statusCode":400}`))),
},
expectedError: Error{
StatusCode: 400,
Err: "invalid_password",
Message: `{"rules":[{"message":"At least %d characters in length","format":[8],"code":"lengthAtLeast","verified":true},{"message":"Contain at least %d of the following %d types of characters:","code":"containsAtLeast","format":[3,4],"items":[{"message":"lower case letters (a-z)","code":"lowerCase","verified":true},{"message":"upper case letters (A-Z)","code":"upperCase","verified":false},{"message":"numbers (i.e. 0-9)","code":"numbers","verified":false},{"message":"special characters (e.g. !@#$%^&*)","code":"specialCharacters","verified":true}],"verified":false}],"verified":false}`,
},
},
}

for _, testCase := range testCases {
23 changes: 16 additions & 7 deletions authentication/authentication_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
"testing"
"time"

_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/stretchr/testify/assert"
@@ -28,12 +28,12 @@ import (
)

var (
domain = os.Getenv("AUTH0_DOMAIN")
clientID = os.Getenv("AUTH0_AUTH_CLIENT_ID")
clientSecret = os.Getenv("AUTH0_AUTH_CLIENT_SECRET")
mgmtClientID = os.Getenv("AUTH0_CLIENT_ID")
mgmtClientSecret = os.Getenv("AUTH0_CLIENT_SECRET")
httpRecordings = os.Getenv("AUTH0_HTTP_RECORDINGS")
domain string
clientID string
clientSecret string
mgmtClientID string
mgmtClientSecret string
httpRecordings string
httpRecordingsEnabled = false
authAPI = &Authentication{}
mgmtAPI = &management.Management{}
@@ -81,6 +81,15 @@ func envVarEnabled(envVar string) bool {
}

func TestMain(m *testing.M) {
_ = godotenv.Load("./../.env", ".env")

domain = os.Getenv("AUTH0_DOMAIN")
clientID = os.Getenv("AUTH0_AUTH_CLIENT_ID")
clientSecret = os.Getenv("AUTH0_AUTH_CLIENT_SECRET")
mgmtClientID = os.Getenv("AUTH0_CLIENT_ID")
mgmtClientSecret = os.Getenv("AUTH0_CLIENT_SECRET")
httpRecordings = os.Getenv("AUTH0_HTTP_RECORDINGS")

httpRecordingsEnabled = envVarEnabled(httpRecordings)

// If we're running in standard `make test` then set a specific clientID and clientSecret
17 changes: 17 additions & 0 deletions management/client.go
Original file line number Diff line number Diff line change
@@ -113,7 +113,11 @@ type Client struct {

// URLs that are valid to call back from Auth0 for OIDC backchannel logout.
// This feature currently must be enabled for your tenant.
// Deprecated: use OIDCLogout instead of OIDCBackchannelLogout.
OIDCBackchannelLogout *OIDCBackchannelLogout `json:"oidc_backchannel_logout,omitempty"`

// URLs that are valid to call back from Auth0 for OIDC logout.
OIDCLogout *OIDCLogout `json:"oidc_logout,omitempty"`
}

// ClientJWTConfiguration is used to configure JWT settings for our Client.
@@ -224,10 +228,23 @@ type PrivateKeyJWT struct {
}

// OIDCBackchannelLogout defines the `oidc_backchannel_logout` settings for the client.
// Deprecated: use OIDCLogout instead of OIDCBackchannelLogout.
type OIDCBackchannelLogout struct {
BackChannelLogoutURLs *[]string `json:"backchannel_logout_urls,omitempty"`
}

// OIDCLogout defines the `oidc_logout` settings for the client.
type OIDCLogout struct {
BackChannelLogoutURLs *[]string `json:"backchannel_logout_urls,omitempty"`
BackChannelLogoutInitiators *BackChannelLogoutInitiators `json:"backchannel_logout_initiators,omitempty"`
}

// BackChannelLogoutInitiators defines the setting for OIDC logout initiators for a Client.
type BackChannelLogoutInitiators struct {
Mode *string `json:"mode,omitempty"`
SelectedInitiators *[]string `json:"selected_initiators,omitempty"`
}

// ClientAddons defines the `addons` settings for a Client.
type ClientAddons struct {
AWS *AWSClientAddon `json:"aws,omitempty"`
31 changes: 31 additions & 0 deletions management/client_test.go
Original file line number Diff line number Diff line change
@@ -126,6 +126,37 @@ func TestClient_CreateWithClientAddons(t *testing.T) {
})
}

func TestClient_CreateWithOIDCLogout(t *testing.T) {
configureHTTPTestRecordings(t)

expectedClient := &Client{
Name: auth0.Stringf("Test Client OIDC Logout (%s)", time.Now().Format(time.StampMilli)),
OIDCLogout: &OIDCLogout{
BackChannelLogoutURLs: &[]string{"https://example.com/logout"},
BackChannelLogoutInitiators: &BackChannelLogoutInitiators{
Mode: auth0.String("custom"),
SelectedInitiators: &[]string{
"rp-logout",
"idp-logout",
},
},
},
}

err := api.Client.Create(context.Background(), expectedClient)
assert.NoError(t, err)
assert.NotEmpty(t, expectedClient.GetClientID())

oidcLogout := expectedClient.GetOIDCLogout()
assert.Equal(t, oidcLogout.GetBackChannelLogoutURLs(), []string{"https://example.com/logout"})
assert.Equal(t, oidcLogout.GetBackChannelLogoutInitiators().GetMode(), "custom")
assert.Equal(t, oidcLogout.GetBackChannelLogoutInitiators().GetSelectedInitiators(), []string{"rp-logout", "idp-logout"})

t.Cleanup(func() {
cleanupClient(t, expectedClient.GetClientID())
})
}

func TestJWTConfiguration(t *testing.T) {
t.Run("MarshalJSON", func(t *testing.T) {
for clientJWTConfiguration, expected := range map[*ClientJWTConfiguration]string{
Loading

0 comments on commit bf6756d

Please sign in to comment.