social-auth: Index | Files | Directories

package social

import ""


Package Files

base.go config.go models.go oauth2.go social.go types.go


var DefaultAppUrl = ""

default redirect url

var DefaultTransport = http.DefaultTransport

default reansport

func GetAllTypes Uses

func GetAllTypes() []SocialType

func GetSocialsByUid Uses

func GetSocialsByUid(uid int, socialTypes ...SocialType) ([]*UserSocial, error)

Get UserSocials by uid

func RegisterProvider Uses

func RegisterProvider(prov Provider) error

Register the social provider

func UserSocials Uses

func UserSocials() orm.QuerySeter

type Cache Uses

type Cache interface {
    Token() (*Token, error)
    PutToken(*Token) error

Cache specifies the methods that implement a Token cache.

type Config Uses

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 Uses

func (c *Config) AuthCodeURL(state string) string

AuthCodeURL returns a URL that the end-user should be redirected to, so that they may obtain an authorization code.

type OAuthError Uses

type OAuthError struct {
    // contains filtered or unexported fields

func (OAuthError) Error Uses

func (oe OAuthError) Error() string

type Provider Uses

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 Uses

func GetProviderByPath(path string) (Provider, bool)

Get provider by path name

func GetProviderByType Uses

func GetProviderByType(typ SocialType) (Provider, bool)

Get provider by SocialType

type SocialAuth Uses

type SocialAuth struct {
    URLPrefix          string
    ConnectSuccessURL  string
    ConnectFailedURL   string
    LoginURL           string
    ConnectRegisterURL string
    // contains filtered or unexported fields

func NewSocial Uses

func NewSocial(urlPrefix string, socialAuther SocialAuther) *SocialAuth

create a global SocialAuth instance

func NewWithFilter Uses

func NewWithFilter(urlPrefix string, socialAuther SocialAuther) *SocialAuth

create a instance and create filter

func (*SocialAuth) ConnectAndLogin Uses

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 Uses

func (this *SocialAuth) OAuthAccess(ctx *context.Context) (redirect string, userSocial *UserSocial, failedErr error)

Callback from social platform

func (*SocialAuth) OAuthRedirect Uses

func (this *SocialAuth) OAuthRedirect(ctx *context.Context) (redirect string, failedErr error)

Redirect to other social platform

func (*SocialAuth) ReadyConnect Uses

func (this *SocialAuth) ReadyConnect(ctx *context.Context) (SocialType, bool)

After OAuthAccess check saved token for ready connect

type SocialAuther Uses

type SocialAuther interface {
    IsUserLogin(*context.Context) (int, bool)
    LoginUser(*context.Context, int) (string, error)

Interface of social utils

type SocialTokenField Uses

type SocialTokenField struct {

func (*SocialTokenField) FieldType Uses

func (e *SocialTokenField) FieldType() int

func (*SocialTokenField) RawValue Uses

func (e *SocialTokenField) RawValue() interface{}

func (*SocialTokenField) SetRaw Uses

func (e *SocialTokenField) SetRaw(value interface{}) error

func (*SocialTokenField) String Uses

func (e *SocialTokenField) String() string

type SocialType Uses

type SocialType int
const (
    SocialGithub SocialType

func (SocialType) Available Uses

func (s SocialType) Available() bool

func (SocialType) Name Uses

func (s SocialType) Name() string

func (SocialType) NameLower Uses

func (s SocialType) NameLower() string

type Token Uses

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.

func (*Token) Expired Uses

func (t *Token) Expired() bool

func (*Token) GetExtra Uses

func (t *Token) GetExtra(key string) string

func (*Token) IsEmpty Uses

func (t *Token) IsEmpty() bool

type Transport Uses

type Transport struct {

    // 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 now contains a valid Token
	r, _, err := t.Client().Get("")

It will automatically refresh the Token if it can, updating the supplied Token in place.

func (*Transport) Client Uses

func (t *Transport) Client() *http.Client

Client returns an *http.Client that makes OAuth-authenticated requests.

func (*Transport) Exchange Uses

func (t *Transport) Exchange(code string) (*Token, error)

Exchange takes a code and gets access Token from the remote server.

func (*Transport) Refresh Uses

func (t *Transport) Refresh() error

Refresh renews the Transport's AccessToken using its RefreshToken.

func (*Transport) RoundTrip Uses

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

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 Uses

type UserSocial struct {
    Id       int
    Uid      int              `orm:"index"`
    Identify string           `orm:"size(200)"`
    Type     SocialType       `orm:"index"`
    Data     SocialTokenField `orm:"null"`

func (*UserSocial) Delete Uses

func (e *UserSocial) Delete() error

func (*UserSocial) Insert Uses

func (e *UserSocial) Insert() error

func (*UserSocial) PutToken Uses

func (e *UserSocial) PutToken(token *Token) error

func (*UserSocial) Read Uses

func (e *UserSocial) Read(fields ...string) error

func (*UserSocial) Save Uses

func (e *UserSocial) Save() (err error)

func (*UserSocial) TableUnique Uses

func (e *UserSocial) TableUnique() [][]string

func (*UserSocial) Token Uses

func (e *UserSocial) Token() (*Token, error)

func (*UserSocial) Update Uses

func (e *UserSocial) Update(fields ...string) error



Package social imports 14 packages (graph) and is imported by 53 packages. Updated 2016-10-30. Refresh now. Tools for package owners.