social

package
v0.0.0-...-eca3c71 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2014 License: MIT Imports: 14 Imported by: 0

README

Beego social auth

Social accounts connect for beego

Support Platform
  • Github
  • Google+
  • Sina Weibo
  • Tencent QQ
  • Dropbox
  • Facebook
Installation
go get github.com/beego/social-auth
Features
  • All use Beego
  • Support multiple social platform.
  • Multiple social accounts can be associated to a single user.
Example

see example project

Project in world:

  • WeTalk a beego community project
Contact

Maintain by slene

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAppUrl = "http://127.0.0.1:8092/"

default redirect url

View Source
var DefaultTransport = http.DefaultTransport

default reansport

Functions

func RegisterProvider

func RegisterProvider(prov Provider) error

Register the social provider

func UserSocials

func UserSocials() orm.QuerySeter

Types

type Cache

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

Cache specifies the methods that implement a Token cache.

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

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

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

func GetProviderByPath(path string) (Provider, bool)

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.

func (*Token) Expired

func (t *Token) Expired() bool

func (*Token) GetExtra

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

func (*Token) IsEmpty

func (t *Token) IsEmpty() bool

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) Client

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

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

func (*Transport) Exchange

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

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

func (*Transport) Refresh

func (t *Transport) Refresh() error

Refresh renews the Transport's AccessToken using its RefreshToken.

func (*Transport) RoundTrip

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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