Skip to content

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

Notifications You must be signed in to change notification settings

telkomdev/go-social

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 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 Authorization Code to the second parameter of GetAccessToken(ctx, "authorization_code") function

package main

import (
	"context"
	"fmt"
	"time"

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

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

        // using context for cancellation
        ctx := context.Background()
        // set context timeout
	ctx, _ = context.WithTimeout(ctx, 2000*time.Millisecond)

	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

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Go 100.0%