Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type AuthorizeRequest struct {
}

type Client interface {
SkipCertificateAuthorityCheck()
CheckCertificateAuthority()
IsAllowed(ar *AuthorizeRequest) (bool, error)
IsRequestAllowed(req *http.Request, resource, permission, owner string) (bool, error)
IsAuthenticated(token string) (bool, error)
Expand Down
35 changes: 28 additions & 7 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"github.com/RangelReale/osin"
Expand All @@ -15,20 +16,40 @@ import (
"strconv"
)

var isAllowed struct {
Allowed bool `json:"allowed"`
}

type client struct {
ep string
token *oauth2.Token
ep string
token *oauth2.Token
skipVerification bool
}

func New(endpoint string, token *oauth2.Token) Client {
return &client{
ep: endpoint,
token: token,
ep: endpoint,
token: token,
skipVerification: true,
}
}

var isAllowed struct {
Allowed bool `json:"allowed"`
func (c *client) newRequest() *gorequest.SuperAgent {
request := gorequest.New()
request.Client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
return request
}

func (c *client) SkipCertificateAuthorityCheck() {
c.skipVerification = true
}

func (c *client) CheckCertificateAuthority() {
c.skipVerification = false
}

func (c *client) IsRequestAllowed(req *http.Request, resource, permission, owner string) (bool, error) {
Expand All @@ -42,7 +63,7 @@ func (c *client) IsRequestAllowed(req *http.Request, resource, permission, owner
}

func (c *client) IsAllowed(ar *AuthorizeRequest) (bool, error) {
request := gorequest.New()
request := c.newRequest()
resp, body, errs := request.Post(c.ep+"/guard/allowed").Set("Authorization", c.token.Type()+" "+c.token.AccessToken).Send(ar).End()
if len(errs) > 0 {
return false, fmt.Errorf("Got errors: %v", errs)
Expand Down
4 changes: 4 additions & 0 deletions client/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func NewAlwaysFalse() Client {
}
}

func (c *client) SkipCertificateAuthorityCheck() {}

func (c *client) CheckCertificateAuthority() {}

func (c *client) IsRequestAllowed(req *http.Request, resource, permission, owner string) (bool, error) {
return c.result, c.err
}
Expand Down