mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-29 15:49:41 +08:00
This pull request introduces the new Flowpilot system along with several new features and various improvements. The key enhancements include configurable authorization, registration, and profile flows, as well as the ability to enable and disable user identifiers (e.g., email addresses and usernames) and login methods. --------- Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io> Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io> Co-authored-by: lfleischmann <67686424+lfleischmann@users.noreply.github.com> Co-authored-by: merlindru <hello@merlindru.com>
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package flowpilot
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gofrs/uuid"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type queryParam interface {
|
|
getKey() string
|
|
getValue() string
|
|
getActionName() ActionName
|
|
getFlowID() uuid.UUID
|
|
getURLValues() url.Values
|
|
}
|
|
|
|
// parsedQueryParamValue represents a parsed action from an input string.
|
|
type parsedQueryParamValue struct {
|
|
actionName ActionName // The actionName of the action extracted from the input string.
|
|
flowID uuid.UUID // The UUID representing the flow ID extracted from the input string.
|
|
}
|
|
|
|
// defaultQueryParam represents a parsed action from an input string.
|
|
type defaultQueryParam struct {
|
|
key string
|
|
|
|
*parsedQueryParamValue
|
|
}
|
|
|
|
func createQueryParamValue(actionName ActionName, flowID uuid.UUID) string {
|
|
return fmt.Sprintf("%s@%s", actionName, flowID)
|
|
}
|
|
|
|
// parseValue parses an input string to extract action name and flow ID.
|
|
func parseQueryParamValue(value string) (*parsedQueryParamValue, error) {
|
|
if value == "" {
|
|
return nil, fmt.Errorf("query param value is empty")
|
|
}
|
|
|
|
// Split the input string into action and flow ID parts using "@" as separator.
|
|
parts := strings.SplitN(value, "@", 2)
|
|
if len(parts) != 2 {
|
|
return nil, fmt.Errorf("invalid query param value format")
|
|
}
|
|
|
|
// Extract action name from the first part of the split.
|
|
action := parts[0]
|
|
if len(action) == 0 {
|
|
return nil, fmt.Errorf("first part of the query param value is empty")
|
|
}
|
|
|
|
// Parse the second part of the input string into a UUID representing the flow ID.
|
|
flowID, err := uuid.FromString(parts[1])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse second part of the query param value: %w", err)
|
|
}
|
|
|
|
// Return a defaultQueryParam instance with extracted action name and flow ID.
|
|
return &parsedQueryParamValue{actionName: ActionName(action), flowID: flowID}, nil
|
|
}
|
|
|
|
func newQueryParam(key, value string) (queryParam, error) {
|
|
v, err := parseQueryParamValue(value)
|
|
return &defaultQueryParam{key: key, parsedQueryParamValue: v}, err
|
|
}
|
|
|
|
func (q *defaultQueryParam) getKey() string {
|
|
return q.key
|
|
}
|
|
|
|
func (q *defaultQueryParam) getValue() string {
|
|
return createQueryParamValue(q.getActionName(), q.getFlowID())
|
|
}
|
|
|
|
func (q *defaultQueryParam) getURLValues() url.Values {
|
|
values := url.Values{}
|
|
values.Add(q.getKey(), q.getValue())
|
|
return values
|
|
}
|
|
|
|
func (q *defaultQueryParam) getActionName() ActionName {
|
|
return q.parsedQueryParamValue.actionName
|
|
}
|
|
|
|
func (q *defaultQueryParam) getFlowID() uuid.UUID {
|
|
return q.parsedQueryParamValue.flowID
|
|
}
|