github.com/greenpau/go-authcrunch@v1.1.4/pkg/requests/requests.go (about)

     1  // Copyright 2022 Paul Greenberg greenpau@outlook.com
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package requests
    16  
    17  import (
    18  	"net/http"
    19  
    20  	"github.com/greenpau/go-authcrunch/pkg/tagging"
    21  
    22  	"go.uber.org/zap"
    23  )
    24  
    25  // Request hold the data associated with identity database
    26  type Request struct {
    27  	ID       string      `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    28  	Upstream Upstream    `json:"upstream,omitempty" xml:"upstream,omitempty" yaml:"upstream,omitempty"`
    29  	Sandbox  Sandbox     `json:"sandbox,omitempty" xml:"sandbox,omitempty" yaml:"sandbox,omitempty"`
    30  	User     User        `json:"user,omitempty" xml:"user,omitempty" yaml:"user,omitempty"`
    31  	Query    Query       `json:"query,omitempty" xml:"query,omitempty" yaml:"query,omitempty"`
    32  	Key      Key         `json:"key,omitempty" xml:"key,omitempty" yaml:"key,omitempty"`
    33  	MfaToken MfaToken    `json:"mfa_token,omitempty" xml:"mfa_token,omitempty" yaml:"mfa_token,omitempty"`
    34  	WebAuthn WebAuthn    `json:"web_authn,omitempty" xml:"web_authn,omitempty" yaml:"web_authn,omitempty"`
    35  	Flags    Flags       `json:"flags,omitempty" xml:"flags,omitempty" yaml:"flags,omitempty"`
    36  	Response Response    `json:"response,omitempty" xml:"response,omitempty" yaml:"response,omitempty"`
    37  	Logger   *zap.Logger `json:"-"`
    38  }
    39  
    40  // Response hold the response associated with identity database
    41  type Response struct {
    42  	Code                int                 `json:"code,omitempty" xml:"code,omitempty" yaml:"code,omitempty"`
    43  	RedirectURL         string              `json:"redirect_url,omitempty" xml:"redirect_url,omitempty" yaml:"redirect_url,omitempty"`
    44  	Payload             interface{}         `json:"-"`
    45  	RedirectTokenName   string              `json:"redirect_token_name,omitempty" xml:"redirect_token_name,omitempty" yaml:"redirect_token_name,omitempty"`
    46  	Authenticated       bool                `json:"authenticated,omitempty" xml:"authenticated,omitempty" yaml:"authenticated,omitempty"`
    47  	Authorized          bool                `json:"authorized,omitempty" xml:"authorized,omitempty" yaml:"authorized,omitempty"`
    48  	IdentityTokenCookie IdentityTokenCookie `json:"-" xml:"-" yaml:"-"`
    49  	// Workflow is the type of workflow the response should follow.
    50  	Workflow string `json:"workflow,omitempty" xml:"workflow,omitempty" yaml:"workflow,omitempty"`
    51  	Title    string `json:"title,omitempty" xml:"title,omitempty" yaml:"title,omitempty"`
    52  	Message  string `json:"message,omitempty" xml:"message,omitempty" yaml:"message,omitempty"`
    53  }
    54  
    55  // IdentityTokenCookie holds the id_token cookie name and payload.
    56  type IdentityTokenCookie struct {
    57  	Name    string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
    58  	Payload string `json:"payload,omitempty" xml:"payload,omitempty" yaml:"payload,omitempty"`
    59  	Enabled bool   `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
    60  }
    61  
    62  // Upstream hold the upstream request handler metadata.
    63  type Upstream struct {
    64  	Request     *http.Request `json:"-"`
    65  	Name        string        `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
    66  	SessionID   string        `json:"session_id,omitempty" xml:"session_id,omitempty" yaml:"session_id,omitempty"`
    67  	BaseURL     string        `json:"base_url,omitempty" xml:"base_url,omitempty" yaml:"base_url,omitempty"`
    68  	BasePath    string        `json:"base_path,omitempty" xml:"base_path,omitempty" yaml:"base_path,omitempty"`
    69  	Method      string        `json:"method,omitempty" xml:"method,omitempty" yaml:"method,omitempty"`
    70  	Realm       string        `json:"realm,omitempty" xml:"realm,omitempty" yaml:"realm,omitempty"`
    71  	ContentType string        `json:"content_type,omitempty" xml:"content_type,omitempty" yaml:"content_type,omitempty"`
    72  	CookieNames []string      `json:"cookie_names,omitempty" xml:"cookie_names,omitempty" yaml:"cookie_names,omitempty"`
    73  }
    74  
    75  // Sandbox hold the data relevant to the user sandbox.
    76  type Sandbox struct {
    77  	ID     string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    78  	View   string `json:"view,omitempty" xml:"view,omitempty" yaml:"view,omitempty"`
    79  	Action string `json:"action,omitempty" xml:"action,omitempty" yaml:"action,omitempty"`
    80  }
    81  
    82  // Query hold request query attributes.
    83  type Query struct {
    84  	ID   string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    85  	Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
    86  }
    87  
    88  // User hold user attributes.
    89  type User struct {
    90  	Username    string   `json:"username,omitempty" xml:"username,omitempty" yaml:"username,omitempty"`
    91  	Email       string   `json:"email,omitempty" xml:"email,omitempty" yaml:"email,omitempty"`
    92  	Password    string   `json:"password,omitempty" xml:"password,omitempty" yaml:"password,omitempty"`
    93  	OldPassword string   `json:"old_password,omitempty" xml:"old_password,omitempty" yaml:"old_password,omitempty"`
    94  	FullName    string   `json:"full_name,omitempty" xml:"full_name,omitempty" yaml:"full_name,omitempty"`
    95  	Roles       []string `json:"roles,omitempty" xml:"roles,omitempty" yaml:"roles,omitempty"`
    96  	Disabled    bool     `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
    97  	Challenges  []string `json:"challenges,omitempty" xml:"challenges,omitempty" yaml:"challenges,omitempty"`
    98  }
    99  
   100  // Key holds crypto key attributes.
   101  type Key struct {
   102  	ID          string        `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
   103  	Prefix      string        `json:"prefix,omitempty" xml:"prefix,omitempty" yaml:"prefix,omitempty"`
   104  	Comment     string        `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
   105  	Usage       string        `json:"usage,omitempty" xml:"usage,omitempty" yaml:"usage,omitempty"`
   106  	Payload     string        `json:"payload,omitempty" xml:"payload,omitempty" yaml:"payload,omitempty"`
   107  	Disabled    bool          `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
   108  	Description string        `json:"description,omitempty" xml:"description,omitempty" yaml:"description,omitempty"`
   109  	IncludeAll  bool          `json:"include_all,omitempty" xml:"include_all,omitempty" yaml:"include_all,omitempty"`
   110  	Tags        []tagging.Tag `json:"tags,omitempty" xml:"tags,omitempty" yaml:"tags,omitempty"`
   111  	Labels      []string      `json:"labels,omitempty" xml:"labels,omitempty" yaml:"labels,omitempty"`
   112  }
   113  
   114  // MfaToken holds MFA token attributes.
   115  type MfaToken struct {
   116  	ID               string        `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
   117  	Comment          string        `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
   118  	Description      string        `json:"description,omitempty" xml:"description,omitempty" yaml:"description,omitempty"`
   119  	Type             string        `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
   120  	Secret           string        `json:"secret,omitempty" xml:"secret,omitempty" yaml:"secret,omitempty"`
   121  	Algorithm        string        `json:"algorithm,omitempty" xml:"algorithm,omitempty" yaml:"algorithm,omitempty"`
   122  	Period           int           `json:"period,omitempty" xml:"period,omitempty" yaml:"period,omitempty"`
   123  	Digits           int           `json:"digits,omitempty" xml:"digits,omitempty" yaml:"digits,omitempty"`
   124  	Passcode         string        `json:"passcode,omitempty" xml:"passcode,omitempty" yaml:"passcode,omitempty"`
   125  	Disabled         bool          `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
   126  	SkipVerification bool          `json:"skip_verification,omitempty" xml:"skip_verification,omitempty" yaml:"skip_verification,omitempty"`
   127  	IncludeAll       bool          `json:"include_all,omitempty" xml:"include_all,omitempty" yaml:"include_all,omitempty"`
   128  	Tags             []tagging.Tag `json:"tags,omitempty" xml:"tags,omitempty" yaml:"tags,omitempty"`
   129  	Labels           []string      `json:"labels,omitempty" xml:"labels,omitempty" yaml:"labels,omitempty"`
   130  }
   131  
   132  // WebAuthn holds WebAuthn messages.
   133  type WebAuthn struct {
   134  	Register  string `json:"register,omitempty" xml:"register,omitempty" yaml:"register,omitempty"`
   135  	Challenge string `json:"challenge,omitempty" xml:"challenge,omitempty" yaml:"challenge,omitempty"`
   136  	Request   string `json:"request,omitempty" xml:"request,omitempty" yaml:"request,omitempty"`
   137  }
   138  
   139  // Flags holds various flags.
   140  type Flags struct {
   141  	Enabled       bool `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
   142  	MfaRequired   bool `json:"mfa_required,omitempty" xml:"mfa_required,omitempty" yaml:"mfa_required,omitempty"`
   143  	MfaConfigured bool `json:"mfa_configured,omitempty" xml:"mfa_configured,omitempty" yaml:"mfa_configured,omitempty"`
   144  	MfaApp        bool `json:"mfa_app,omitempty" xml:"mfa_app,omitempty" yaml:"mfa_app,omitempty"`
   145  	MfaUniversal  bool `json:"mfa_universal,omitempty" xml:"mfa_universal,omitempty" yaml:"mfa_universal,omitempty"`
   146  }
   147  
   148  // NewRequest returns an instance of Request.
   149  func NewRequest() *Request {
   150  	return &Request{}
   151  }