serviceprovider

package
v0.1.1-beta Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FACEBOOK service provider
	FACEBOOK = "FACEBOOK"

	// GOOGLE service provider
	GOOGLE = "GOOGLE"
)

Functions

This section is empty.

Types

type AccessTokenSchema

type AccessTokenSchema struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
	ExpiresIn   int32  `json:"expires_in"`
}

AccessTokenSchema is a schema for parsing token object from the service provider

type Facebook

type Facebook struct {
	ServiceProvider  string
	GraphURL         string
	OauthURL         string
	ClientID         string
	ClientSecret     string
	OauthRedirectURI string
	OauthScope       string
	Fields           string
}

Facebook represents the Facebook service provider

func (*Facebook) GenerateAccessToken

func (fb *Facebook) GenerateAccessToken(uri string) (*AccessTokenSchema, error)

GenerateAccessToken generates a Facebook access token

func (*Facebook) GenerateGetAccessTokenURI

func (fb *Facebook) GenerateGetAccessTokenURI(code string) string

GenerateGetAccessTokenURI returns an oauth URI to generate access token from Facebook

func (*Facebook) GenerateGetProfileURI

func (fb *Facebook) GenerateGetProfileURI(accessToken string) string

GenerateGetProfileURI returns a URI to get Facebook profile

func (*Facebook) GenerateOauthURI

func (fb *Facebook) GenerateOauthURI() string

GenerateOauthURI returns an oauth URI that will be use by the M9 to redirect to Facebook to the generate the code

func (*Facebook) Get

func (fb *Facebook) Get() string

Get returns service provider

func (*Facebook) GetProfile

func (fb *Facebook) GetProfile(uri string) (*map[string]interface{}, error)

GetProfile returns the Facebook profile using the generated access token

type Google

type Google struct {
	ServiceProvider  string
	APIURL           string
	OauthURL         string
	OauthTokenURL    string
	ClientID         string
	ClientSecret     string
	OauthRedirectURI string
	OauthScope       string
}

Google represents the Google service provider

func (*Google) GenerateAccessToken

func (g *Google) GenerateAccessToken(uri string) (*AccessTokenSchema, error)

GenerateAccessToken generates a Google access token

func (*Google) GenerateGetAccessTokenURI

func (g *Google) GenerateGetAccessTokenURI(code string) string

GenerateGetAccessTokenURI returns an oauth URI to generate access token from Google

func (*Google) GenerateGetProfileURI

func (g *Google) GenerateGetProfileURI(accessToken string) string

GenerateGetProfileURI returns a URI to get Google profile

func (*Google) GenerateOauthURI

func (g *Google) GenerateOauthURI() string

GenerateOauthURI returns an oauth URI that will be use by the M9 to redirect to Google to the generate the code

func (*Google) Get

func (g *Google) Get() string

Get returns service provider

func (*Google) GetProfile

func (g *Google) GetProfile(uri string) (*map[string]interface{}, error)

GetProfile returns the Google profile using the generated access token

type IProvider

type IProvider interface {
	Get() string

	GenerateOauthURI() string
	GenerateGetAccessTokenURI(code string) string
	GenerateGetProfileURI(accessToken string) string

	GenerateAccessToken(uri string) (*AccessTokenSchema, error)
	GetProfile(uri string) (*map[string]interface{}, error)
}

IProvider is an interface that should be implemented when creating a service provider object

func New

func New(serviceProvider string) (IProvider, error)

New initates service provider object based on provided service provider

func NewFacebook

func NewFacebook() IProvider

NewFacebook initiates Faceboook service provider

func NewGoogle

func NewGoogle() IProvider

NewGoogle initiates Google service provider

Jump to

Keyboard shortcuts

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