Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 1.76 KB

README.md

File metadata and controls

65 lines (43 loc) · 1.76 KB

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