This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: #20 bootstrap data retrieve endpoint #46
Merged
+277
−23
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package operation | ||
|
||
type createOIDCRequestResponse struct { | ||
Request string `json:"request"` | ||
} | ||
|
||
type bootstrapData struct { | ||
SDSURL string `json:"sdsURL"` | ||
SDSPrimaryVaultID string `json:"sdsPrimaryVaultID"` | ||
KeyServerURL string `json:"keyServerURL"` | ||
KeyStoreIDs []string `json:"keyStoreIDs"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,9 @@ import ( | |
) | ||
|
||
const ( | ||
oauth2GetRequestPath = "/oauth2/request" | ||
oauth2CallbackPath = "/oauth2/callback" | ||
oauth2GetRequestPath = "/oauth2/request" | ||
oauth2CallbackPath = "/oauth2/callback" | ||
bootstrapGetRequestPath = "/bootstrap" | ||
// api path params | ||
scopeQueryParam = "scope" | ||
|
||
|
@@ -117,6 +118,7 @@ type Operation struct { | |
oidcCallbackURL string | ||
oauth2ConfigFunc func(...string) oauth2Config | ||
bootstrapStore storage.Store | ||
bootstrapConfig *BootstrapConfig | ||
} | ||
|
||
// Config defines configuration for rp operations. | ||
|
@@ -129,10 +131,13 @@ type Config struct { | |
OIDCCallbackURL string | ||
TransientStoreProvider storage.Provider | ||
StoreProvider storage.Provider | ||
BootstrapConfig *BootstrapConfig | ||
} | ||
|
||
type createOIDCRequestResponse struct { | ||
Request string `json:"request"` | ||
// BootstrapConfig holds user bootstrap-related config. | ||
type BootstrapConfig struct { | ||
SDSURL string | ||
KeyServerURL string | ||
} | ||
|
||
// New returns rp operation instance. | ||
|
@@ -143,6 +148,7 @@ func New(config *Config) (*Operation, error) { | |
oidcClientID: config.OIDCClientID, | ||
oidcClientSecret: config.OIDCClientSecret, | ||
oidcCallbackURL: config.OIDCCallbackURL, | ||
bootstrapConfig: config.BootstrapConfig, | ||
} | ||
|
||
// TODO implement retries: https://github.com/trustbloc/hub-auth/issues/45 | ||
|
@@ -340,6 +346,48 @@ func (c *Operation) onboardUser(id string) (*user.Profile, error) { | |
return userProfile, nil | ||
} | ||
|
||
func (c *Operation) handleBootstrapDataRequest(w http.ResponseWriter, r *http.Request) { | ||
handle := r.URL.Query().Get("up") | ||
if handle == "" { | ||
handleAuthError(w, http.StatusBadRequest, "missing handle") | ||
|
||
return | ||
} | ||
|
||
profile, err := user.NewStore(c.transientStore).Get(handle) | ||
if errors.Is(err, storage.ErrValueNotFound) { | ||
handleAuthError(w, http.StatusBadRequest, "invalid handle") | ||
|
||
return | ||
} | ||
|
||
if err != nil { | ||
handleAuthError(w, http.StatusInternalServerError, | ||
fmt.Sprintf("failed to query transient store for handle: %s", err)) | ||
|
||
return | ||
} | ||
|
||
response, err := json.Marshal(&bootstrapData{ | ||
SDSURL: c.bootstrapConfig.SDSURL, | ||
SDSPrimaryVaultID: profile.SDSPrimaryVaultID, | ||
KeyServerURL: c.bootstrapConfig.KeyServerURL, | ||
KeyStoreIDs: profile.KeyStoreIDs, | ||
}) | ||
if err != nil { | ||
handleAuthError(w, http.StatusInternalServerError, fmt.Sprintf("failed to marshal bootstrap data: %s", err)) | ||
|
||
return | ||
} | ||
|
||
// TODO We should delete the handle from the transient store after writing the response, | ||
// but edge-core store API doesn't have a Delete() operation: https://github.com/trustbloc/edge-core/issues/45 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if not having the Delete() operation is blocking you and I can work on it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DRK3 it's not blocking for now but should be there if we are going to say this thing is "production-ready" |
||
_, err = w.Write(response) | ||
if err != nil { | ||
logger.Errorf("failed to write bootstrap data to output: %s", err) | ||
} | ||
} | ||
|
||
// TODO redirect to the UI: https://github.com/trustbloc/hub-auth/issues/39 | ||
func handleAuthResult(w http.ResponseWriter, r *http.Request, _ *user.Profile) { | ||
http.Redirect(w, r, "", http.StatusFound) | ||
|
@@ -373,6 +421,7 @@ func (c *Operation) GetRESTHandlers() []Handler { | |
return []Handler{ | ||
support.NewHTTPHandler(oauth2GetRequestPath, http.MethodGet, c.createOIDCRequest), | ||
support.NewHTTPHandler(oauth2CallbackPath, http.MethodGet, c.handleOIDCCallback), | ||
support.NewHTTPHandler(bootstrapGetRequestPath, http.MethodGet, c.handleBootstrapDataRequest), | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "up"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DRK3 stands for "user profile", and is being added in #43