{"id":13740439,"url":"https://github.com/danilopolani/gocialite","last_synced_at":"2025-05-08T20:31:17.910Z","repository":{"id":56050259,"uuid":"111706693","full_name":"danilopolani/gocialite","owner":"danilopolani","description":"Social oAuth login in Go has never been so easy","archived":true,"fork":false,"pushed_at":"2023-06-27T19:34:41.000Z","size":51,"stargazers_count":248,"open_issues_count":8,"forks_count":45,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-23T11:58:19.059Z","etag":null,"topics":["driver","gin-tonic","go","golang","golang-library","golang-package","oauth","social-login","social-oauth","socialite"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danilopolani.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-11-22T16:17:44.000Z","updated_at":"2024-06-08T19:23:31.000Z","dependencies_parsed_at":"2024-01-07T18:10:07.185Z","dependency_job_id":null,"html_url":"https://github.com/danilopolani/gocialite","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Fgocialite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Fgocialite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Fgocialite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Fgocialite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danilopolani","download_url":"https://codeload.github.com/danilopolani/gocialite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224765461,"owners_count":17366123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["driver","gin-tonic","go","golang","golang-library","golang-package","oauth","social-login","social-oauth","socialite"],"created_at":"2024-08-03T04:00:47.856Z","updated_at":"2024-11-15T10:30:40.311Z","avatar_url":"https://github.com/danilopolani.png","language":"Go","funding_links":[],"categories":["Authorization","Authorization Development"],"sub_categories":["\u003ca name=\"authZ-golang\"\u003e\u003c/a\u003eGolang"],"readme":"# Gocialite\n![Travis CI build](https://api.travis-ci.org/danilopolani/gocialite.svg?branch=master)\n![Available Drivers](https://img.shields.io/badge/Drivers-5+-orange.svg)\n[![GoDoc](https://godoc.org/github.com/danilopolani/gocialite?status.svg)](https://godoc.org/github.com/danilopolani/gocialite)\n[![GoReport](https://goreportcard.com/badge/github.com/danilopolani/gocialite)](https://goreportcard.com/report/github.com/danilopolani/gocialite)\n![GitHub contributors](https://img.shields.io/github/contributors/danilopolani/gocialite.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n## NOT MAINTAINED\nThis project is no longer maintained, you should over a more robust solution like [Goth](https://github.com/markbates/goth).  \n\n----\n\nGocialite is a Socialite inspired package to manage social oAuth authentication without problems.\nThe idea was born when I discovered that Goth is not so flexible: I was using Revel and it was *impossible* to connect them properly.\n\n## Installation\n\nTo install it, just run `go get gopkg.in/danilopolani/gocialite.v1` and include it in your app: `import \"gopkg.in/danilopolani/gocialite.v1\"`.\n\n## Available drivers\n\n- Amazon\n- Asana\n- Bitbucket\n- Facebook\n- Foursquare\n- Github\n- Google\n- LinkedIn\n- Slack\n\n## Create new driver\n\nPlease see [Contributing page](https://github.com/danilopolani/gocialite/blob/master/CONTRIBUTING.md) to learn how to create new driver and test it.\n\n## Set scopes\n\n**Note**: Gocialite set some default scopes for the user profile, for example for *Facebook* it specify `email` and for *Google* `profile, email`.  \nWhen you use the following method, you don't have to rewrite them. \n\nUse the `Scopes([]string)` method of your `Gocial` instance. Example:\n\n```go\ngocial.Scopes([]string{\"public_repo\"})\n```\n\n## Set driver\n\nUse the `Driver(string)` method of your `Gocial` instance. Example:\n\n```go\ngocial.Driver(\"facebook\")\n```\n\nThe driver name will be the provider name in lowercase.\n\n## How to use it\n\n**Note**: All Gocialite methods are chainable.\n\nDeclare a \"global\" variable outside your `main` func:\n\n```go\nimport (\n\t...\n)\n\nvar gocial = gocialite.NewDispatcher()\n\nfunc main() {\n```\n\nThen create a route to use as redirect bridge, for example `/auth/github`. With this route, the user will be redirected to the provider oAuth login. In this case we use Gin Tonic as router. You have to specify the provider with the `Driver()` method.\nThen, with `Scopes()`, you can set a list of scopes as slice of strings. It's optional.  \nFinally, with `Redirect()` you can obtain the redirect URL. In this method you have to pass three parameters:\n\n1. Client ID\n1. Client Secret\n1. Redirect URL\n\n```go\nfunc main() {\n\trouter := gin.Default()\n\n\trouter.GET(\"/auth/github\", redirectHandler)\n\n\trouter.Run(\"127.0.0.1:9090\")\n}\n\n// Redirect to correct oAuth URL\nfunc redirectHandler(c *gin.Context) {\n\tauthURL, err := gocial.New().\n\t\tDriver(\"github\"). // Set provider\n\t\tScopes([]string{\"public_repo\"}). // Set optional scope(s)\n\t\tRedirect( // \n\t\t\t\"xxxxxxxxxxxxxx\", // Client ID\n\t\t\t\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\", // Client Secret\n\t\t\t\"http://localhost:9090/auth/github/callback\", // Redirect URL\n\t\t)\n\n\t// Check for errors (usually driver not valid)\n\tif err != nil {\n\t\tc.Writer.Write([]byte(\"Error: \" + err.Error()))\n\t\treturn\n\t}\n\n\t// Redirect with authURL\n\tc.Redirect(http.StatusFound, authURL) // Redirect with 302 HTTP code\n}\n```\n\nNow create a callback handler route, where we'll receive the content from the provider.  \nIn order to validate the oAuth and retrieve the data, you have to invoke the `Handle()` method with two query parameters: `state` and `code`. In your URL, they will look like this: `http://localhost:9090/auth/github/callback?state=xxxxxxxx\u0026code=xxxxxxxx`.  \nThe `Handle()` method returns the user info, the token and error if there's one or `nil`.  \nIf there are no errors, in the `user` variable you will find the logged in user information and in the `token` one, the token info (it's a [oauth2.Token struct](https://godoc.org/golang.org/x/oauth2#Token)). The data of the user - which is a [gocialite.User struct](https://github.com/danilopolani/gocialite/blob/master/structs/user.go) - are the following:\n\n- ID\n- FirstName\n- LastName\n- FullName\n- Email\n- Avatar (URL)\n- Raw (the full JSON returned by the provider)\n\nNote that they can be empty.\n\n```go\nfunc main() {\n\trouter := gin.Default()\n\n\trouter.GET(\"/auth/github\", redirectHandler)\n\trouter.GET(\"/auth/github/callback\", callbackHandler)\n\n\trouter.Run(\"127.0.0.1:9090\")\n}\n\n// Redirect to correct oAuth URL\n// Handle callback of provider\nfunc callbackHandler(c *gin.Context) {\n\t// Retrieve query params for code and state\n\tcode := c.Query(\"code\")\n\tstate := c.Query(\"state\")\n\n\t// Handle callback and check for errors\n\tuser, token, err := gocial.Handle(state, code)\n\tif err != nil {\n\t\tc.Writer.Write([]byte(\"Error: \" + err.Error()))\n\t\treturn\n\t}\n\n\t// Print in terminal user information\n\tfmt.Printf(\"%#v\", token)\n\tfmt.Printf(\"%#v\", user)\n\n\t// If no errors, show provider name\n\tc.Writer.Write([]byte(\"Hi, \" + user.FullName))\n}\n```\n\nPlease take a look to [multi provider example](https://github.com/danilopolani/gocialite/wiki/Multi-provider-example) for a full working code with Gin Tonic and variable provider handler.\n\n## Contributors\n\n- [Danilo Polani](https://github.com/danilopolani)\n- [Joseph Buchma](https://github.com/josephbuchma)\n- [Mark Beznos](https://github.com/vibbix)\n- [Davor Kapsa](https://github.com/dvrkps)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Fgocialite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilopolani%2Fgocialite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Fgocialite/lists"}