-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve and add support for more openapi security schemes
- Loading branch information
1 parent
c03793a
commit 5ad2716
Showing
27 changed files
with
423 additions
and
1,053 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,34 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"github.com/cerberauth/vulnapi/jwt" | ||
) | ||
|
||
type BearerSecurityScheme struct { | ||
Type Type `json:"type" yaml:"type"` | ||
Scheme SchemeName `json:"scheme" yaml:"scheme"` | ||
In SchemeIn `json:"in" yaml:"in"` | ||
Name string `json:"name" yaml:"name"` | ||
ValidValue *string `json:"-" yaml:"-"` | ||
AttackValue string `json:"-" yaml:"-"` | ||
} | ||
|
||
var _ SecurityScheme = (*BearerSecurityScheme)(nil) | ||
|
||
func NewAuthorizationBearerSecurityScheme(name string, value *string) *BearerSecurityScheme { | ||
return &BearerSecurityScheme{ | ||
Type: HttpType, | ||
Scheme: BearerScheme, | ||
In: InHeader, | ||
Name: name, | ||
ValidValue: value, | ||
AttackValue: "", | ||
func NewAuthorizationBearerSecurityScheme(name string, value *string) (*SecurityScheme, error) { | ||
in := InHeader | ||
tokenFormat := NoneTokenFormat | ||
if value != nil && *value != "" && jwt.IsJWT(*value) { | ||
tokenFormat = JWTTokenFormat | ||
} | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetType() Type { | ||
return ss.Type | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetScheme() SchemeName { | ||
return ss.Scheme | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetIn() *SchemeIn { | ||
return &ss.In | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetName() string { | ||
return ss.Name | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetHeaders() http.Header { | ||
header := http.Header{} | ||
attackValue := ss.GetAttackValue().(string) | ||
if attackValue == "" && ss.HasValidValue() { | ||
attackValue = ss.GetValidValue().(string) | ||
securityScheme, err := NewSecurityScheme(name, nil, HttpType, BearerScheme, &in, &tokenFormat) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if attackValue != "" { | ||
header.Set(AuthorizationHeader, fmt.Sprintf("%s %s", BearerPrefix, attackValue)) | ||
err = securityScheme.SetValidValue(value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return header | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetCookies() []*http.Cookie { | ||
return []*http.Cookie{} | ||
return securityScheme, nil | ||
} | ||
|
||
func (ss *BearerSecurityScheme) HasValidValue() bool { | ||
return ss.ValidValue != nil && *ss.ValidValue != "" | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetValidValue() interface{} { | ||
if !ss.HasValidValue() { | ||
return nil | ||
func MustNewAuthorizationBearerSecurityScheme(name string, value *string) *SecurityScheme { | ||
securityScheme, err := NewAuthorizationBearerSecurityScheme(name, value) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return *ss.ValidValue | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetValidValueWriter() interface{} { | ||
return nil | ||
} | ||
|
||
func (ss *BearerSecurityScheme) SetAttackValue(v interface{}) { | ||
ss.AttackValue = v.(string) | ||
} | ||
|
||
func (ss *BearerSecurityScheme) GetAttackValue() interface{} { | ||
return ss.AttackValue | ||
return securityScheme | ||
} |
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
Oops, something went wrong.