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

Host Credential Issuer Metadata in a separate executable #330

Merged
merged 12 commits into from
Mar 23, 2023

Conversation

andresuribe87
Copy link
Contributor

@andresuribe87 andresuribe87 commented Mar 17, 2023

copilot:all

Overview

This PR does two things:
2. Hosts the credential issuer metadata in /.well-known/openid-credential-issuer.
3. Enabled users of the service to specify a path where they want to have their own custom metadata.

Description

I intentionally tried to keep this simple.

How Has This Been Tested?

Added a simple unit test that fetches from the endpoint.

Checklist

Before submitting this PR, please make sure:

  • I have read the CONTRIBUTING document.
  • My code is consistent with the rest of the project
  • I have tagged the relevant reviewers and/or interested parties
  • I have updated the READMEs and other documentation of affected packages

References

https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-issuer-metadata-

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Merging #330 (769a780) into main (b8783ec) will increase coverage by 0.33%.
The diff coverage is 82.60%.

@@            Coverage Diff             @@
##             main     #330      +/-   ##
==========================================
+ Coverage   18.77%   19.11%   +0.33%     
==========================================
  Files          36       38       +2     
  Lines        4356     4379      +23     
==========================================
+ Hits          818      837      +19     
- Misses       3416     3418       +2     
- Partials      122      124       +2     
Impacted Files Coverage Δ
pkg/authorizationserver/issuermetadata.go 63.63% <63.63%> (ø)
pkg/authorizationserver/oauth2.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

oauth2.WriteAuthorizeError(ctx, rw, ar, err)
return nil
}
if req.PostForm.Get("username") != "peter" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to leave this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where we plug in our auth logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed now. Will be part of a separate PR.

"github.com/tbd54566975/ssi-service/pkg/server/middleware"
)

// fosite requires four parameters for the server to get up and running:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these official oauth files and we should't change them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was scaffolding from https://github.com/ory/fosite-example

I will be modifying this a bunch in subsequent PRs. I've simplified this now to be the bare minimum for hosting the issuer metadata.

// If you require this to key to be stable, for example, when running multiple fosite servers, you can generate the
// 32byte random key as above and push it out to a base64 encoded string.
// This can then be injected and decoded as the `var secret []byte` on server start.
secret = []byte("some-cool-secret-that-is-32bytes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can read this from config

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or env var

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed now.

@michaelneale
Copy link
Contributor

copilot:summary

// Allow retrieval of credential issuer metadata according to https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-issuer-metadata
func credentialIssuerMetadata(config *AuthConfig) func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
// It's ok to panic inside this function because this is only called during startup.
jsonData, err := os.ReadFile(config.CredentialIssuerFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is the same file being retrieved over and over we can cache it in memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually cached! This function is only run once, during the setup of the server. If you look closely, this function returns another function. The latter uses the already read file.

@andresuribe87 andresuribe87 merged commit 160a186 into TBD54566975:main Mar 23, 2023
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.

5 participants