Documentation
      ¶
    
    
  
    
  
    Index ¶
- func NewActorContext(ctx context.Context, a Actor) context.Context
 - type Actor
 - type Client
 - func (c *Client) Actor(ctx context.Context, token string) (*Actor, error)
 - func (c *Client) FromContext(ctx context.Context) (*Actor, error)
 - func (c *Client) IsAuthenticated(ctx context.Context, token string) (bool, error)
 - func (c *Client) IsGranted(ctx context.Context, userID int64, perm charon.Permission) (bool, error)
 - func (c *Client) Login(ctx context.Context, username, password string) (string, error)
 - func (c *Client) Logout(ctx context.Context, token string) error
 
- type Options
 - type SecurityContext
 
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Actor ¶
type Actor struct {
	ID          int64              `json:"id"`
	Username    string             `json:"username"`
	FirstName   string             `json:"firstName"`
	LastName    string             `json:"lastName"`
	IsSuperuser bool               `json:"isSuperuser"`
	IsActive    bool               `json:"isActive"`
	IsStaff     bool               `json:"isStaff"`
	IsConfirmed bool               `json:"isConfirmed"`
	Permissions charon.Permissions `json:"permissions"`
}
    Actor is a generic object that represent anything that can be under control of charon.
type Client ¶
type Client struct {
	// contains filtered or unexported fields
}
    Client is simplified version of rpc AuthClient. It contains most commonly used methods. For more powerful low level API check RPCClient interface.
func New ¶
func New(conn *grpc.ClientConn, options ...Options) *Client
New allocates new Charon instance with given options.
func (*Client) FromContext ¶
FromContext implements Charon interface.
func (*Client) IsAuthenticated ¶
IsAuthenticated implements Charon interface.
type Options ¶
type Options func(*charonOptions)
Options configures how we set up the Client.
func WithMetadata ¶
WithMetadata sets metadata that will be attachable to every request.
type SecurityContext ¶
type SecurityContext interface {
	context.Context
	oauth2.TokenSource
	// Actor ...
	Actor() (Actor, bool)
	// AccessToken ...
	AccessToken() (string, bool)
}
    SecurityContext ....
Example ¶
token := "0000000001some hash"
subject := Actor{
	ID:       1,
	Username: "j.kowalski@gmail.com",
}
ctx := NewActorContext(context.Background(), subject)
ctx = mnemosyne.NewAccessTokenContext(ctx, token)
sctx := NewSecurityContext(ctx)
var (
	t   *oauth2.Token
	act Actor
	err error
	ok  bool
)
if t, err = sctx.Token(); err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
} else {
	fmt.Println(t.AccessToken)
}
if act, ok = sctx.Actor(); ok {
	fmt.Println(act.ID)
	fmt.Println(act.Username)
}
Output: 0000000001some hash 1 j.kowalski@gmail.com
func NewSecurityContext ¶
func NewSecurityContext(ctx context.Context) SecurityContext
NewSecurityContext allocates new context.
 Click to show internal directories. 
   Click to hide internal directories.