github.com/greenpau/go-identity@v1.1.6/pkg/requests/requests.go (about)

     1  // Copyright 2020 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  	"go.uber.org/zap"
    19  	"net/http"
    20  )
    21  
    22  // Request hold the data associated with identity database
    23  type Request struct {
    24  	ID       string      `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    25  	Upstream Upstream    `json:"upstream,omitempty" xml:"upstream,omitempty" yaml:"upstream,omitempty"`
    26  	Sandbox  Sandbox     `json:"sandbox,omitempty" xml:"sandbox,omitempty" yaml:"sandbox,omitempty"`
    27  	User     User        `json:"user,omitempty" xml:"user,omitempty" yaml:"user,omitempty"`
    28  	Query    Query       `json:"query,omitempty" xml:"query,omitempty" yaml:"query,omitempty"`
    29  	Key      Key         `json:"key,omitempty" xml:"key,omitempty" yaml:"key,omitempty"`
    30  	MfaToken MfaToken    `json:"mfa_token,omitempty" xml:"mfa_token,omitempty" yaml:"mfa_token,omitempty"`
    31  	WebAuthn WebAuthn    `json:"web_authn,omitempty" xml:"web_authn,omitempty" yaml:"web_authn,omitempty"`
    32  	Flags    Flags       `json:"flags,omitempty" xml:"flags,omitempty" yaml:"flags,omitempty"`
    33  	Response Response    `json:"response,omitempty" xml:"response,omitempty" yaml:"response,omitempty"`
    34  	Logger   *zap.Logger `json:"-"`
    35  }
    36  
    37  // Response hold the response associated with identity database
    38  type Response struct {
    39  	Code              int         `json:"code,omitempty" xml:"code,omitempty" yaml:"code,omitempty"`
    40  	RedirectURL       string      `json:"redirect_url,omitempty" xml:"redirect_url,omitempty" yaml:"redirect_url,omitempty"`
    41  	Payload           interface{} `json:"-"`
    42  	RedirectTokenName string      `json:"redirect_token_name,omitempty" xml:"redirect_token_name,omitempty" yaml:"redirect_token_name,omitempty"`
    43  	Authenticated     bool        `json:"authenticated,omitempty" xml:"authenticated,omitempty" yaml:"authenticated,omitempty"`
    44  	Authorized        bool        `json:"authorized,omitempty" xml:"authorized,omitempty" yaml:"authorized,omitempty"`
    45  	// Workflow is the type of workflow the response should follow.
    46  	Workflow string `json:"workflow,omitempty" xml:"workflow,omitempty" yaml:"workflow,omitempty"`
    47  	Title    string `json:"title,omitempty" xml:"title,omitempty" yaml:"title,omitempty"`
    48  	Message  string `json:"message,omitempty" xml:"message,omitempty" yaml:"message,omitempty"`
    49  }
    50  
    51  // Upstream hold the upstream request handler metadata.
    52  type Upstream struct {
    53  	Request     *http.Request `json:"-"`
    54  	Name        string        `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
    55  	SessionID   string        `json:"session_id,omitempty" xml:"session_id,omitempty" yaml:"session_id,omitempty"`
    56  	BaseURL     string        `json:"base_url,omitempty" xml:"base_url,omitempty" yaml:"base_url,omitempty"`
    57  	BasePath    string        `json:"base_path,omitempty" xml:"base_path,omitempty" yaml:"base_path,omitempty"`
    58  	Method      string        `json:"method,omitempty" xml:"method,omitempty" yaml:"method,omitempty"`
    59  	Realm       string        `json:"realm,omitempty" xml:"realm,omitempty" yaml:"realm,omitempty"`
    60  	ContentType string        `json:"content_type,omitempty" xml:"content_type,omitempty" yaml:"content_type,omitempty"`
    61  	CookieNames []string      `json:"cookie_names,omitempty" xml:"cookie_names,omitempty" yaml:"cookie_names,omitempty"`
    62  }
    63  
    64  // Sandbox hold the data relevant to the user sandbox.
    65  type Sandbox struct {
    66  	ID     string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    67  	View   string `json:"view,omitempty" xml:"view,omitempty" yaml:"view,omitempty"`
    68  	Action string `json:"action,omitempty" xml:"action,omitempty" yaml:"action,omitempty"`
    69  }
    70  
    71  // Query hold request query attributes.
    72  type Query struct {
    73  	ID   string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    74  	Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"`
    75  }
    76  
    77  // User hold user attributes.
    78  type User struct {
    79  	Username    string   `json:"username,omitempty" xml:"username,omitempty" yaml:"username,omitempty"`
    80  	Email       string   `json:"email,omitempty" xml:"email,omitempty" yaml:"email,omitempty"`
    81  	Password    string   `json:"password,omitempty" xml:"password,omitempty" yaml:"password,omitempty"`
    82  	OldPassword string   `json:"old_password,omitempty" xml:"old_password,omitempty" yaml:"old_password,omitempty"`
    83  	FullName    string   `json:"full_name,omitempty" xml:"full_name,omitempty" yaml:"full_name,omitempty"`
    84  	Roles       []string `json:"roles,omitempty" xml:"roles,omitempty" yaml:"roles,omitempty"`
    85  	Disabled    bool     `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
    86  	Challenges  []string `json:"challenges,omitempty" xml:"challenges,omitempty" yaml:"challenges,omitempty"`
    87  }
    88  
    89  // Key holds crypto key attributes.
    90  type Key struct {
    91  	ID       string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    92  	Prefix   string `json:"prefix,omitempty" xml:"prefix,omitempty" yaml:"prefix,omitempty"`
    93  	Comment  string `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
    94  	Usage    string `json:"usage,omitempty" xml:"usage,omitempty" yaml:"usage,omitempty"`
    95  	Payload  string `json:"payload,omitempty" xml:"payload,omitempty" yaml:"payload,omitempty"`
    96  	Disabled bool   `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
    97  }
    98  
    99  // MfaToken holds MFA token attributes.
   100  type MfaToken struct {
   101  	ID        string `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
   102  	Comment   string `json:"comment,omitempty" xml:"comment,omitempty" yaml:"comment,omitempty"`
   103  	Type      string `json:"type,omitempty" xml:"type,omitempty" yaml:"type,omitempty"`
   104  	Secret    string `json:"secret,omitempty" xml:"secret,omitempty" yaml:"secret,omitempty"`
   105  	Algorithm string `json:"algorithm,omitempty" xml:"algorithm,omitempty" yaml:"algorithm,omitempty"`
   106  	Period    int    `json:"period,omitempty" xml:"period,omitempty" yaml:"period,omitempty"`
   107  	Digits    int    `json:"digits,omitempty" xml:"digits,omitempty" yaml:"digits,omitempty"`
   108  	Passcode  string `json:"passcode,omitempty" xml:"passcode,omitempty" yaml:"passcode,omitempty"`
   109  	Disabled  bool   `json:"disabled,omitempty" xml:"disabled,omitempty" yaml:"disabled,omitempty"`
   110  }
   111  
   112  // WebAuthn holds WebAuthn messages.
   113  type WebAuthn struct {
   114  	Register  string `json:"register,omitempty" xml:"register,omitempty" yaml:"register,omitempty"`
   115  	Challenge string `json:"challenge,omitempty" xml:"challenge,omitempty" yaml:"challenge,omitempty"`
   116  	Request   string `json:"request,omitempty" xml:"request,omitempty" yaml:"request,omitempty"`
   117  }
   118  
   119  // Flags holds various flags.
   120  type Flags struct {
   121  	Enabled       bool `json:"enabled,omitempty" xml:"enabled,omitempty" yaml:"enabled,omitempty"`
   122  	MfaRequired   bool `json:"mfa_required,omitempty" xml:"mfa_required,omitempty" yaml:"mfa_required,omitempty"`
   123  	MfaConfigured bool `json:"mfa_configured,omitempty" xml:"mfa_configured,omitempty" yaml:"mfa_configured,omitempty"`
   124  	MfaApp        bool `json:"mfa_app,omitempty" xml:"mfa_app,omitempty" yaml:"mfa_app,omitempty"`
   125  	MfaUniversal  bool `json:"mfa_universal,omitempty" xml:"mfa_universal,omitempty" yaml:"mfa_universal,omitempty"`
   126  }
   127  
   128  // NewRequest returns an instance of Request.
   129  func NewRequest() *Request {
   130  	return &Request{}
   131  }