xauth

package module
v0.0.0-...-da93e03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 20 Imported by: 0

README

README

配置

r.GET("/login/:oauth", core.Handle(login.Oauth))

[app]
secretKey = "ASDFASDFASDF" # hashStatecode
rootURL = "http://localhost:9001"
baseURL = "/login/"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingTeamMembership         = &Error{"User not a member of one of the required teams"}
	ErrMissingOrganizationMembership = &Error{"User not a member of one of the required organizations"}
)
View Source
var (
	ConnectorMap = make(map[string]Connector)
)
View Source
var (
	ErrMissingGroupMembership = &Error{"User not a member of one of the required groups"}
)
View Source
var (
	OauthStateCookieName = "oauth_state"
)

Functions

func GenStateString

func GenStateString() (string, error)

func HashStateCode

func HashStateCode(secretKey, code, seed string) string

func NewOAuthService

func NewOAuthService(appURL, baseURL string, auths []OAuthInfo)

func ParseAppAndSubURL

func ParseAppAndSubURL(rootURL string) (string, string, error)

Types

type Base

type Base struct {
	*oauth2.Config
	// contains filtered or unexported fields
}

func (*Base) IsEmailAllowed

func (s *Base) IsEmailAllowed(email string) bool

func (*Base) IsSignupAllowed

func (s *Base) IsSignupAllowed() bool

type BasicUserInfo

type BasicUserInfo struct {
	Id      string
	Name    string
	Email   string
	Login   string
	Company string
	Role    string
	Groups  []string
}

type Connector

type Connector interface {
	Type() int
	UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)
	IsEmailAllowed(email string) bool
	IsSignupAllowed() bool

	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
	Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	Client(ctx context.Context, token *oauth2.Token) *http.Client
	TokenSource(ctx context.Context, token *oauth2.Token) oauth2.TokenSource
}

Connector ..

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

type GithubTeam

type GithubTeam struct {
	Id           int    `json:"id"`
	Slug         string `json:"slug"`
	URL          string `json:"html_url"`
	Organization struct {
		Login string `json:"login"`
	} `json:"organization"`
}

func (*GithubTeam) GetShorthand

func (t *GithubTeam) GetShorthand() (string, error)

type HttpGetResponse

type HttpGetResponse struct {
	Body    []byte
	Headers http.Header
}

func HttpGet

func HttpGet(client *http.Client, url string) (response HttpGetResponse, err error)

type OAuthInfo

type OAuthInfo struct {
	Typ                  string
	ClientId             string
	ClientSecret         string
	Scopes               []string
	AuthUrl              string
	TokenUrl             string
	Enable               bool
	EmailAttributeName   string
	EmailAttributePath   string
	RoleAttributePath    string
	AllowedDomains       []string
	HostedDomain         string
	ApiUrl               string
	AllowSignup          bool
	Name                 string
	TlsClientCert        string
	TlsClientKey         string
	TlsClientCa          string
	TlsSkipVerify        bool
	TeamIds              []interface{}
	AllowedOrganizations []string
	AllowedGroups        []string
}

type OAuthType

type OAuthType int
const (
	GITHUB OAuthType = iota + 1
	GOOGLE
	GENERIC
	GRAFANA
	GITLAB
)

type OAuths

type OAuths struct {
	OAuthInfos map[string]*OAuthInfo
}
var OAuthService *OAuths

type OrgRecord

type OrgRecord struct {
	Login string `json:"login"`
}

type SocialGenericOAuth

type SocialGenericOAuth struct {
	*Base
	// contains filtered or unexported fields
}

func (*SocialGenericOAuth) FetchOrganizations

func (s *SocialGenericOAuth) FetchOrganizations(client *http.Client) ([]string, bool)

func (*SocialGenericOAuth) FetchPrivateEmail

func (s *SocialGenericOAuth) FetchPrivateEmail(client *http.Client) (string, error)

func (*SocialGenericOAuth) FetchTeamMemberships

func (s *SocialGenericOAuth) FetchTeamMemberships(client *http.Client) ([]int, bool)

func (*SocialGenericOAuth) IsOrganizationMember

func (s *SocialGenericOAuth) IsOrganizationMember(client *http.Client) bool

func (*SocialGenericOAuth) IsTeamMember

func (s *SocialGenericOAuth) IsTeamMember(client *http.Client) bool

func (*SocialGenericOAuth) Type

func (s *SocialGenericOAuth) Type() int

func (*SocialGenericOAuth) UserInfo

func (s *SocialGenericOAuth) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)

type SocialGithub

type SocialGithub struct {
	*Base
	// contains filtered or unexported fields
}

func (*SocialGithub) FetchOrganizations

func (s *SocialGithub) FetchOrganizations(client *http.Client, organizationsUrl string) ([]string, error)

func (*SocialGithub) FetchPrivateEmail

func (s *SocialGithub) FetchPrivateEmail(client *http.Client) (string, error)

func (*SocialGithub) FetchTeamMemberships

func (s *SocialGithub) FetchTeamMemberships(client *http.Client) ([]GithubTeam, error)

func (*SocialGithub) HasMoreRecords

func (s *SocialGithub) HasMoreRecords(headers http.Header) (string, bool)

func (*SocialGithub) IsOrganizationMember

func (s *SocialGithub) IsOrganizationMember(client *http.Client, organizationsUrl string) bool

func (*SocialGithub) IsTeamMember

func (s *SocialGithub) IsTeamMember(client *http.Client) bool

func (*SocialGithub) Type

func (s *SocialGithub) Type() int

func (*SocialGithub) UserInfo

func (s *SocialGithub) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)

type SocialGitlab

type SocialGitlab struct {
	*Base
	// contains filtered or unexported fields
}

func (*SocialGitlab) GetGroups

func (s *SocialGitlab) GetGroups(client *http.Client) []string

func (*SocialGitlab) GetGroupsPage

func (s *SocialGitlab) GetGroupsPage(client *http.Client, url string) ([]string, string)

GetGroupsPage returns groups and link to the next page if response is paginated

func (*SocialGitlab) IsGroupMember

func (s *SocialGitlab) IsGroupMember(groups []string) bool

func (*SocialGitlab) Type

func (s *SocialGitlab) Type() int

func (*SocialGitlab) UserInfo

func (s *SocialGitlab) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)

type SocialGoogle

type SocialGoogle struct {
	*Base
	// contains filtered or unexported fields
}

func (*SocialGoogle) Type

func (s *SocialGoogle) Type() int

func (*SocialGoogle) UserInfo

func (s *SocialGoogle) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)

type SocialGrafanaCom

type SocialGrafanaCom struct {
	*Base
	// contains filtered or unexported fields
}

func (*SocialGrafanaCom) IsEmailAllowed

func (s *SocialGrafanaCom) IsEmailAllowed(email string) bool

func (*SocialGrafanaCom) IsOrganizationMember

func (s *SocialGrafanaCom) IsOrganizationMember(organizations []OrgRecord) bool

func (*SocialGrafanaCom) Type

func (s *SocialGrafanaCom) Type() int

func (*SocialGrafanaCom) UserInfo

func (s *SocialGrafanaCom) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error)

type UserInfoJson

type UserInfoJson struct {
	Name        string              `json:"name"`
	DisplayName string              `json:"display_name"`
	Login       string              `json:"login"`
	Username    string              `json:"username"`
	Email       string              `json:"email"`
	Upn         string              `json:"upn"`
	Attributes  map[string][]string `json:"attributes"`
	// contains filtered or unexported fields
}

func (*UserInfoJson) String

func (info *UserInfoJson) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL