Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client credentials Private Key JWT auth for management API #528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ErwinSteffens
Copy link
Contributor

🔧 Changes

Add client credentials Private Key JWT auth for management API.

The x/oauth2 package allows for adding extra EndpointParams to client credentials config which allows for Private Key JWT to be used without implementation in the library. If we use AuthStyleInParams, but do not add client ID or Secret, they will not get added to the request params.

There is an open issue for implementing this in the library, but there seems to be no traction anymore for a long time. Therefore I wanted to suggest this solution.

If ok, I can start adding tests for it.

📚 References

🔬 Testing

  • Generate key pair with:
    • openssl genrsa -out private.pem 2048
    • openssl rsa -in private.pem -pubout > public.pub
  • Add new application in Auth0
  • Setup Private Key JWT auth for the application and add the public key

Run following main.go program:

package main

import (
	"context"
	"log"
	"os"

	"github.com/auth0/go-auth0/management"
)

func main() {
	signingAlg := "RS256"
	auth0Domain := "auth0Domain"
	clientID := "clientId"

	key, err := os.ReadFile("private.pem")
	if err != nil {
		panic(err)
	}

	auth0API, err := management.New(
		auth0Domain,
		management.WithClientCredentialsPrivateKeyJwt(context.TODO(), signingAlg, string(key), clientID),
	)
	if err != nil {
		panic(err)
	}

	test, err := auth0API.Client.List(context.TODO(), management.Page(0), management.PerPage(10))
	if err != nil {
		panic(err)
	}

	log.Println("Auth0 clients: %+v", test)
}

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant