Documentation ¶
Index ¶
- Variables
- func RegisterProvider(prov Provider) error
- func UserSocials() orm.QuerySeter
- type Cache
- type Config
- type OAuthError
- type Provider
- type SocialAuth
- func (this *SocialAuth) ConnectAndLogin(ctx *context.Context, socialType SocialType, uid int) (string, *UserSocial, error)
- func (this *SocialAuth) OAuthAccess(ctx *context.Context) (redirect string, userSocial *UserSocial, failedErr error)
- func (this *SocialAuth) OAuthRedirect(ctx *context.Context) (redirect string, failedErr error)
- func (this *SocialAuth) ReadyConnect(ctx *context.Context) (SocialType, bool)
- type SocialAuther
- type SocialTokenField
- type SocialType
- type Token
- type Transport
- type UserSocial
- func (e *UserSocial) Delete() error
- func (e *UserSocial) Insert() error
- func (e *UserSocial) PutToken(token *Token) error
- func (e *UserSocial) Read(fields ...string) error
- func (e *UserSocial) Save() (err error)
- func (e *UserSocial) TableUnique() [][]string
- func (e *UserSocial) Token() (*Token, error)
- func (e *UserSocial) Update(fields ...string) error
Constants ¶
This section is empty.
Variables ¶
var DefaultAppUrl = "http://127.0.0.1:8092/"
default redirect url
var DefaultTransport = http.DefaultTransport
default reansport
Functions ¶
func UserSocials ¶
func UserSocials() orm.QuerySeter
Types ¶
type Config ¶
type Config struct { // ClientId is the OAuth client identifier used when communicating with // the configured OAuth provider. ClientId string // ClientSecret is the OAuth client secret used when communicating with // the configured OAuth provider. ClientSecret string // Scope identifies the level of access being requested. Multiple scope // values should be provided as a space-delimited string. Scope string // AuthURL is the URL the user will be directed to in order to grant // access. AuthURL string // TokenURL is the URL used to retrieve OAuth tokens. TokenURL string // RedirectURL is the URL to which the user will be returned after // granting (or denying) access. RedirectURL string // TokenCache allows tokens to be cached for subsequent requests. TokenCache Cache AccessType string // Optional, "online" (default) or "offline", no refresh token if "online" // ApprovalPrompt indicates whether the user should be // re-prompted for consent. If set to "auto" (default) the // user will be prompted only if they haven't previously // granted consent and the code can only be exchanged for an // access token. // If set to "force" the user will always be prompted, and the // code can be exchanged for a refresh token. ApprovalPrompt string }
Config is the configuration of an OAuth consumer.
func (*Config) AuthCodeURL ¶
AuthCodeURL returns a URL that the end-user should be redirected to, so that they may obtain an authorization code.
type OAuthError ¶
type OAuthError struct {
// contains filtered or unexported fields
}
func (OAuthError) Error ¶
func (oe OAuthError) Error() string
type Provider ¶
type Provider interface { GetConfig() *Config GetType() SocialType GetName() string GetPath() string GetIndentify(*Token) (string, error) CanConnect(*Token, *UserSocial) (bool, error) }
Interface of social Privider
func GetProviderByPath ¶
Get provider by path name
func GetProviderByType ¶
func GetProviderByType(typ SocialType) (Provider, bool)
Get provider by SocialType
type SocialAuth ¶
type SocialAuth struct { URLPrefix string ConnectSuccessURL string ConnectFailedURL string LoginURL string ConnectRegisterURL string // contains filtered or unexported fields }
func NewSocial ¶
func NewSocial(urlPrefix string, socialAuther SocialAuther) *SocialAuth
create a global SocialAuth instance
func NewWithFilter ¶
func NewWithFilter(urlPrefix string, socialAuther SocialAuther) *SocialAuth
create a instance and create filter
func (*SocialAuth) ConnectAndLogin ¶
func (this *SocialAuth) ConnectAndLogin(ctx *context.Context, socialType SocialType, uid int) (string, *UserSocial, error)
save user social info and login the user
func (*SocialAuth) OAuthAccess ¶
func (this *SocialAuth) OAuthAccess(ctx *context.Context) (redirect string, userSocial *UserSocial, failedErr error)
Callback from social platform
func (*SocialAuth) OAuthRedirect ¶
func (this *SocialAuth) OAuthRedirect(ctx *context.Context) (redirect string, failedErr error)
Redirect to other social platform
func (*SocialAuth) ReadyConnect ¶
func (this *SocialAuth) ReadyConnect(ctx *context.Context) (SocialType, bool)
After OAuthAccess check saved token for ready connect
type SocialAuther ¶
type SocialAuther interface { IsUserLogin(*context.Context) (int, bool) LoginUser(*context.Context, int) (string, error) }
Interface of social utils
type SocialTokenField ¶
type SocialTokenField struct {
*Token
}
func (*SocialTokenField) FieldType ¶
func (e *SocialTokenField) FieldType() int
func (*SocialTokenField) RawValue ¶
func (e *SocialTokenField) RawValue() interface{}
func (*SocialTokenField) SetRaw ¶
func (e *SocialTokenField) SetRaw(value interface{}) error
func (*SocialTokenField) String ¶
func (e *SocialTokenField) String() string
type SocialType ¶
type SocialType int
const ( SocialGithub SocialType SocialGoogle SocialWeibo SocialQQ SocialDropbox SocialFacebook )
func GetAllTypes ¶
func GetAllTypes() []SocialType
func (SocialType) Available ¶
func (s SocialType) Available() bool
func (SocialType) Name ¶
func (s SocialType) Name() string
func (SocialType) NameLower ¶
func (s SocialType) NameLower() string
type Token ¶
type Token struct { AccessToken string TokenType string Expiry time.Time // If zero the token has no (known) expiry time. RefreshToken string Extra map[string]string // May be nil. }
Token contains an end-user's tokens. This is the data you must store to persist authentication.
type Transport ¶
type Transport struct { *Config *Token // Transport is the HTTP transport to use when making requests. // It will default to http.DefaultTransport if nil. // (It should never be an oauth.Transport.) Transport http.RoundTripper }
Transport implements http.RoundTripper. When configured with a valid Config and Token it can be used to make authenticated HTTP requests.
t := &oauth.Transport{config} t.Exchange(code) // t now contains a valid Token r, _, err := t.Client().Get("http://example.org/url/requiring/auth")
It will automatically refresh the Token if it can, updating the supplied Token in place.
func (*Transport) RoundTrip ¶
RoundTrip executes a single HTTP transaction using the Transport's Token as authorization headers.
This method will attempt to renew the Token if it has expired and may return an error related to that Token renewal before attempting the client request. If the Token cannot be renewed a non-nil os.Error value will be returned. If the Token is invalid callers should expect HTTP-level errors, as indicated by the Response's StatusCode.
type UserSocial ¶
type UserSocial struct { Id int Uid int `orm:"index"` Identify string `orm:"size(200)"` Type SocialType `orm:"index"` Data SocialTokenField `` }
func GetSocialsByUid ¶
func GetSocialsByUid(uid int, socialTypes ...SocialType) ([]*UserSocial, error)
Get UserSocials by uid
func (*UserSocial) Delete ¶
func (e *UserSocial) Delete() error
func (*UserSocial) Insert ¶
func (e *UserSocial) Insert() error
func (*UserSocial) PutToken ¶
func (e *UserSocial) PutToken(token *Token) error
func (*UserSocial) Read ¶
func (e *UserSocial) Read(fields ...string) error
func (*UserSocial) Save ¶
func (e *UserSocial) Save() (err error)
func (*UserSocial) TableUnique ¶
func (e *UserSocial) TableUnique() [][]string
func (*UserSocial) Token ¶
func (e *UserSocial) Token() (*Token, error)
func (*UserSocial) Update ¶
func (e *UserSocial) Update(fields ...string) error