{"id":26262037,"url":"https://github.com/aaomidi/go-paseto-middleware","last_synced_at":"2025-04-30T09:21:46.480Z","repository":{"id":57548928,"uuid":"133176174","full_name":"aaomidi/go-paseto-middleware","owner":"aaomidi","description":"Paseto middleware for GoLang","archived":false,"fork":false,"pushed_at":"2021-09-23T20:55:05.000Z","size":24,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-26T13:12:31.377Z","etag":null,"topics":["auth","authentication","go","golang","middleware","paseto","past","token"],"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/aaomidi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-12T19:13:19.000Z","updated_at":"2023-07-07T05:00:36.000Z","dependencies_parsed_at":"2022-08-28T09:23:40.915Z","dependency_job_id":null,"html_url":"https://github.com/aaomidi/go-paseto-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaomidi%2Fgo-paseto-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaomidi%2Fgo-paseto-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaomidi%2Fgo-paseto-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaomidi%2Fgo-paseto-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaomidi","download_url":"https://codeload.github.com/aaomidi/go-paseto-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251674990,"owners_count":21625717,"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":["auth","authentication","go","golang","middleware","paseto","past","token"],"created_at":"2025-03-14T00:17:14.806Z","updated_at":"2025-04-30T09:21:46.459Z","avatar_url":"https://github.com/aaomidi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GO Paseto Middleware\n[![License](http://img.shields.io/:license-mit-blue.svg)](LICENSE)\n[![Travis](https://travis-ci.com/aaomidi/go-paseto-middleware.svg?branch=master\u0026style=flat-square)](https://travis-ci.com/aaomidi/go-paseto-middleware)\n[![Go Report Card](https://goreportcard.com/badge/github.com/aaomidi/go-paseto-middleware)](https://goreportcard.com/report/github.com/aaomidi/go-paseto-middleware)\n[![GoDoc](https://godoc.org/github.com/aaomidi/go-paseto-middleware?status.svg)](https://godoc.org/github.com/aaomidi/go-paseto-middleware)\n\n\nA middleware that will check that a Paseto token is sent in a request. It will then set the contents of the token into the context of the request.\n\nThis module allows you authenticate HTTP requests using Paseto.\n\n## Installing\n\n````bash\ngo get github.com/aaomidi/go-paseto-middleware\n````\n\n## Using it\n\nThis library is written for use with [o1egl's paseto library](https://github.com/o1egl/paseto).\n\nYou can use the `pasetomiddleware` with default `net/http` as follows:\n\n````golang\npackage auth\n\ntype Backend struct {\n\tsecretKey string\n}\n\nfunc Auth() *Backend {\n\tif authBackendInstance == nil {\n\t\tauthBackendInstance = \u0026Backend{\n\t\t\tsecretKey: \"YELLOW SUBMARINE, BLACK WIZARDRY\", // Obviously don't use this exact string.\n\t\t}\n\t}\n\n\treturn authBackendInstance\n}\n\nfunc (backend *Backend) Middleware(optional bool) *pasetomiddleware.PasetoMiddleware {\n\tmiddleware, _ := pasetomiddleware.New(\n\t\tpasetomiddleware.Extractor(func(r *http.Request) (string, error) {\n\t\t\tcookie, err := r.Cookie(\"paseto\")\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\treturn cookie.Value, nil\n\t\t}),\n\n\t\tpasetomiddleware.Decryptor(func(pas string, token *paseto.JSONToken, footer *string) error {\n\t\t\tv2 := paseto.NewV2()\n\t\t\terr := v2.Decrypt(pas, []byte(backend.secretKey), token, footer)\n\t\t\treturn err\n\t\t}),\n\t\tpasetomiddleware.CredentialsOptional(optional),\n\n\t\tpasetomiddleware.Debug(optional),\n\t)\n\n\treturn middleware\n}\n````\n\n````golang\n    package api\n\n    router := mux.newRouter()\n\n    router.Handle(\"/profile\", auth.Auth().Middleware(false).NextFunc(profile)).Methods(\"GET\")\n    // You can also use .Next(http.Handler) to add another middleware.\n````\n\nTo get the token from the request, you will do the following:\n\n\n````golang\n// This is initiated before.\nvar authedMiddleware *pasetomiddleware.PasetoMiddleware\n\nfunc getUUIDFromRequest(r *http.Request) (uuid.UUID, error) {\n\tt, ok := r.Context().Value(authedMiddleware.TokenProperty).(*paseto.JSONToken)\n\tif !ok {\n\t\treturn uuid.New(), errors.New(\"token not valid\")\n\t}\n\n    // I put the UUID string with the user key into the token Map\n\tid := t.Get(\"user\")\n\tif id == \"\" {\n\t\treturn uuid.New(), errors.New(\"token not valid\")\n\t}\n\n    // Parses the UUID\n\tuid, err := uuid.Parse(fmt.Sprint(id))\n\treturn uid, err\n}\n````\n\n# Inspiration\n\nThis project was heavily inspired by [GO-JWT-Middleware](https://github.com/auth0/go-jwt-middleware).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaomidi%2Fgo-paseto-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaomidi%2Fgo-paseto-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaomidi%2Fgo-paseto-middleware/lists"}