{"id":21485538,"url":"https://github.com/m0a/goagooglelogin","last_synced_at":"2025-09-13T12:06:45.505Z","repository":{"id":144279472,"uuid":"92578996","full_name":"m0a/goagooglelogin","owner":"m0a","description":"google login middleware for goa","archived":false,"fork":false,"pushed_at":"2018-02-04T13:03:38.000Z","size":16745,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-13T12:02:36.960Z","etag":null,"topics":["goa","middleware"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m0a.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-27T07:08:51.000Z","updated_at":"2018-03-11T04:59:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"525ed1bc-e67d-4122-9046-966e18418c65","html_url":"https://github.com/m0a/goagooglelogin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/m0a/goagooglelogin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0a%2Fgoagooglelogin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0a%2Fgoagooglelogin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0a%2Fgoagooglelogin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0a%2Fgoagooglelogin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m0a","download_url":"https://codeload.github.com/m0a/goagooglelogin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0a%2Fgoagooglelogin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274957017,"owners_count":25380833,"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","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["goa","middleware"],"created_at":"2024-11-23T13:16:26.439Z","updated_at":"2025-09-13T12:06:45.485Z","avatar_url":"https://github.com/m0a.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# googlelogin goa middleware\n\nsimple google login midleware for ``goa``\n\nplease check example [standard](https://github.com/m0a/goagooglelogin/tree/master/examples/simple) or [GAE/go sample](https://github.com/m0a/goagooglelogin/tree/master/examples/gae)\n\n\n# how to use\n\n## setting desgin\n\nrequire setup JWTSecurity\n\n```go\n\nvar JWT = JWTSecurity(\"jwt\", func() {\n\tHeader(\"Authorization\")\n\tScope(\"api:access\", \"API access\") // Define \"api:access\" scope\n})\n\n// use JWT securety\n\nvar _ = Resource(\"sample\", func() {\n\tDescription(\"This resource uses JWT to secure its endpoints\")\n\tDefaultMedia(SuccessMedia)\n\n\t// Use JWT to auth requests to this endpoint\n\tSecurity(JWT, func() { \n\t\tScope(\"api:access\")\n\t})\n\n\tAction(\"secure\", func() {\n\t\tDescription(\"This action is secured with the jwt scheme\")\n\t\tRouting(GET(\"/jwt\"))\n\t\tResponse(OK, SecureMedia)\n\t\tResponse(Unauthorized)\n\t})\n\n})\n\n```\n\n## edit main.go\n\n### setup conf\n\nrequired GoogleClientID and GoogleClientSecret and CreateClaims\n\n```go\n\n\t// for sample savecode\n\taccounts := map[string]controllers.Account{} \n\n\tconf := \u0026goagooglelogin.DefaultGoaGloginConf\n\tconf.GoogleClientID = os.Getenv(\"OPENID_GOOGLE_CLIENT\")\n\tconf.GoogleClientSecret = os.Getenv(\"OPENID_GOOGLE_SECRET\")\n\n\tconf.CreateClaims = func(\n\t\tctx context.Context\n\t\tgoogleUserID string,\n\t\tuserinfo *oauth2.Userinfoplus, tokenInfo *oauth2.Tokeninfo) (claims jwt.Claims, err error) {\n\t\tresp, err := http.Get(userinfo.Picture)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\n\t\t}\n\t\tdefer resp.Body.Close()\n\t\tpicture, err := ioutil.ReadAll(resp.Body)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tfmt.Println(len(picture))\n\n\t\t// sample save code\n\t\t_, ok := accounts[googleUserID]\n\t\tif !ok {\n\t\t\taccount := controllers.Account{\n\t\t\t\tGoogleUserID: googleUserID,\n\t\t\t\tImage:        picture,\n\t\t\t\tEmail:        userinfo.Email,\n\t\t\t\tName:         userinfo.Name,\n\t\t\t\tCreated:      time.Now(),\n\t\t\t}\n\t\t\taccounts[googleUserID] = account\n\t\t}\n\n\t\treturn goagooglelogin.MakeClaim(\"api:access\", googleUserID, 10), nil\n\t}\n\n```\n\n### use midlaware and mount controllers\n\n```go\n\tapp.UseJWTMiddleware(service, goagooglelogin.NewJWTMiddleware(conf, app.NewJWTSecurity()))\n\n\tgoagooglelogin.MountControllerWithConfig(service, conf)\n```\n\n## edit controllers\n\nget googleID from GoogleIDByJWTContext.\n\n```go\nfunc (c *SampleController) Secure(ctx *app.SampleJWTContext) error {\n\n\tgoogleID, err := goagooglelogin.GoogleIDByJWTContext(ctx)\n\n\tif err != nil {\n\t\treturn ctx.Unauthorized()\n\t}\n\n\tif c.Accounts == nil {\n\t\treturn ctx.Unauthorized()\n\t}\n\taccount, ok := (*c.Accounts)[googleID]\n\tif !ok {\n\t\treturn ctx.Unauthorized()\n\t}\n\n\timg := base64.StdEncoding.EncodeToString(account.Image)\n\tres := app.GoaExamplesSecuritySecure{\n\t\tName:  \u0026account.Name,\n\t\tEmail: \u0026account.Email,\n\t\tImage: \u0026img,\n\t}\n\treturn ctx.OK(\u0026res)\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm0a%2Fgoagooglelogin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm0a%2Fgoagooglelogin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm0a%2Fgoagooglelogin/lists"}