Skip to content

a Pluggable OAuth client library for social login (Google, Facebook, Github, Linkedin, Microsoft Identity Platform)

Notifications You must be signed in to change notification settings

wuriyanto48/go-social

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pluggable OAuth library for social login (Google, Facebook, Github, Linkedin)

GoDoc Build Status CircleCI

forthebadge forthebadge forthebadge

Install

$ go get github.com/wuriyanto48/go-social

Usage

OAuth2 using Facebook login

  • Getting Authorization Code First https://www.facebook.com/dialog/oauth?client_id={your_client_id}&redirect_uri=http://localhost:8080/callback&response_type=code

  • Place the Authorization Code to the second parameter of GetAccessToken(ctx, "authorization_code") function

package main

import (
	"context"
	"fmt"

	"github.com/wuriyanto48/go-social"
	"github.com/wuriyanto48/go-social/pkg/facebook"
)

func main() {
	f, err := social.New(social.Facebook, "client_id", "client_secret", "", "http://localhost:8080/callback", "", 0)

	if err != nil {
		fmt.Println(err)
	}
	
	// using context for cancellation
	ctx := context.Background()

	err = f.GetAccessToken(ctx, "authorization_code")

	if err != nil {
		fmt.Println(err)
	}

	result, err := f.GetUser(ctx)

	if err != nil {
		fmt.Println(err)
	}

	user, _ := result.(*facebook.User)

	fmt.Println(user.Picture)
}

Todo

  • Add Twitter implementation