Skip to content

Commit

Permalink
Changed DID to subject
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Sep 13, 2024
1 parent adff851 commit 0a05ad0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions nuts/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TokenSource(nutsAPIURL string, ownDID string) *OAuth2TokenSource {
var _ oauth2.TokenSource = &OAuth2TokenSource{}

type OAuth2TokenSource struct {
OwnDID string
NutsSubject string
// NutsAPIURL is the base URL of the Nuts node API.
NutsAPIURL string
// NutsHttpClient is the HTTP client used to communicate with the Nuts node.
Expand All @@ -34,7 +34,7 @@ type OAuth2TokenSource struct {
}

func (o OAuth2TokenSource) Token(httpRequest *http.Request, authzServerURL *url.URL, scope string) (*oauth2.Token, error) {
if o.OwnDID == "" {
if o.NutsSubject == "" {
return nil, fmt.Errorf("ownDID is required")
}
var additionalCredentials []vc.VerifiableCredential
Expand All @@ -48,7 +48,7 @@ func (o OAuth2TokenSource) Token(httpRequest *http.Request, authzServerURL *url.
// TODO: Might want to support DPoP as well
var tokenType = iam.ServiceAccessTokenRequestTokenTypeBearer
// TODO: Is this the right context to use?
response, err := client.RequestServiceAccessToken(httpRequest.Context(), o.OwnDID, iam.RequestServiceAccessTokenJSONRequestBody{
response, err := client.RequestServiceAccessToken(httpRequest.Context(), o.NutsSubject, iam.RequestServiceAccessTokenJSONRequestBody{
AuthorizationServer: authzServerURL.String(),
Credentials: &additionalCredentials,
Scope: scope,
Expand Down
12 changes: 6 additions & 6 deletions nuts/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
func TestOAuth2TokenSource_Token(t *testing.T) {
t.Run("ok", func(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/internal/auth/v2/did:web:example.com/request-service-access-token", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/internal/auth/v2/123abc/request-service-access-token", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"access_token":"test","token_type":"bearer","expires_in":3600}`))
})
httpServer := httptest.NewServer(mux)
tokenSource := OAuth2TokenSource{
OwnDID: "did:web:example.com",
NutsAPIURL: httpServer.URL,
NutsSubject: "123abc",
NutsAPIURL: httpServer.URL,
}
expectedAuthServerURL, _ := url.Parse("https://auth.example.com")
httpRequest, _ := http.NewRequestWithContext(context.Background(), "GET", "https://resource.example.com", nil)
Expand All @@ -43,16 +43,16 @@ func TestOAuth2TokenSource_Token(t *testing.T) {
t.Run("additional credentials", func(t *testing.T) {
mux := http.NewServeMux()
var capturedRequest iam.ServiceAccessTokenRequest
mux.HandleFunc("/internal/auth/v2/did:web:example.com/request-service-access-token", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/internal/auth/v2/123abc/request-service-access-token", func(w http.ResponseWriter, r *http.Request) {
require.NoError(t, json.NewDecoder(r.Body).Decode(&capturedRequest))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"access_token":"test","token_type":"bearer","expires_in":3600}`))
})
httpServer := httptest.NewServer(mux)
tokenSource := OAuth2TokenSource{
OwnDID: "did:web:example.com",
NutsAPIURL: httpServer.URL,
NutsSubject: "123abc",
NutsAPIURL: httpServer.URL,
}
expectedAuthServerURL, _ := url.Parse("https://auth.example.com")
requestCtx := WithAdditionalCredentials(context.Background(), []vc.VerifiableCredential{
Expand Down

0 comments on commit 0a05ad0

Please sign in to comment.