├── .gitignore ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── Feature Request.yml │ └── Bug Report.yml ├── dependabot.yml ├── workflows │ └── semgrep.yml └── stale.yml ├── 01-Login ├── .gitignore ├── .dockerignore ├── exec.ps1 ├── exec.sh ├── .env.example ├── web │ ├── static │ │ ├── js │ │ │ ├── user.js │ │ │ └── js.cookie.js │ │ ├── image │ │ │ └── auth0_logo_final_blue_RGB.png │ │ └── css │ │ │ └── app.css │ ├── app │ │ ├── home │ │ │ └── home.go │ │ ├── user │ │ │ └── user.go │ │ ├── logout │ │ │ └── logout.go │ │ ├── login │ │ │ └── login.go │ │ └── callback │ │ │ └── callback.go │ └── template │ │ ├── home.html │ │ └── user.html ├── platform │ ├── middleware │ │ └── isAuthenticated.go │ ├── router │ │ └── router.go │ └── authenticator │ │ └── auth.go ├── Dockerfile ├── main.go ├── go.mod ├── README.md └── go.sum ├── LICENSE ├── README.md └── .circleci └── config.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @auth0-samples/dx-sdks-engineer 2 | -------------------------------------------------------------------------------- /01-Login/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .DS_Store 3 | src/ 4 | pkg/ 5 | -------------------------------------------------------------------------------- /01-Login/.dockerignore: -------------------------------------------------------------------------------- 1 | .env.example 2 | .gitignore 3 | README.md 4 | exec.sh 5 | exec.ps1 6 | src/ 7 | pkg/ 8 | -------------------------------------------------------------------------------- /01-Login/exec.ps1: -------------------------------------------------------------------------------- 1 | docker build -t auth0-golang-web-app . 2 | docker run --env-file .env -p 3000:3000 -it auth0-golang-web-app 3 | -------------------------------------------------------------------------------- /01-Login/exec.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | docker build -t auth0-golang-web-app . 3 | docker run --env-file .env -p 3000:3000 -it auth0-golang-web-app 4 | -------------------------------------------------------------------------------- /01-Login/.env.example: -------------------------------------------------------------------------------- 1 | AUTH0_CLIENT_ID={CLIENT_ID} 2 | AUTH0_DOMAIN={DOMAIN} 3 | AUTH0_CLIENT_SECRET={CLIENT_SECRET} 4 | AUTH0_CALLBACK_URL=http://localhost:3000/callback 5 | -------------------------------------------------------------------------------- /01-Login/web/static/js/user.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $('.btn-logout').click(function(e) { 3 | Cookies.remove('auth-session'); 4 | }); 5 | }); 6 | -------------------------------------------------------------------------------- /01-Login/web/static/image/auth0_logo_final_blue_RGB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-samples/auth0-golang-web-app/HEAD/01-Login/web/static/image/auth0_logo_final_blue_RGB.png -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: 🤔 Help & Questions 4 | url: https://community.auth0.com 5 | about: Ask general support or usage questions in the Auth0 Community forums. 6 | -------------------------------------------------------------------------------- /01-Login/web/app/home/home.go: -------------------------------------------------------------------------------- 1 | package home 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | // Handler for our home page. 10 | func Handler(ctx *gin.Context) { 11 | ctx.HTML(http.StatusOK, "home.html", nil) 12 | } 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" 4 | directory: "/01-Login" 5 | schedule: 6 | interval: "daily" 7 | ignore: 8 | - dependency-name: "*" 9 | update-types: ["version-update:semver-major", "version-update:semver-patch"] 10 | -------------------------------------------------------------------------------- /01-Login/web/app/user/user.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-contrib/sessions" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // Handler for our logged-in user page. 11 | func Handler(ctx *gin.Context) { 12 | session := sessions.Default(ctx) 13 | profile := session.Get("profile") 14 | 15 | ctx.HTML(http.StatusOK, "user.html", profile) 16 | } 17 | -------------------------------------------------------------------------------- /01-Login/platform/middleware/isAuthenticated.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-contrib/sessions" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // IsAuthenticated is a middleware that checks if 11 | // the user has already been authenticated previously. 12 | func IsAuthenticated(ctx *gin.Context) { 13 | if sessions.Default(ctx).Get("profile") == nil { 14 | ctx.Redirect(http.StatusSeeOther, "/") 15 | } else { 16 | ctx.Next() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /01-Login/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.19.3-alpine3.17 2 | 3 | # Define current working directory 4 | WORKDIR /01-Login 5 | 6 | # Download modules to local cache so we can skip re- 7 | # downloading on consecutive docker build commands 8 | COPY go.mod . 9 | COPY go.sum . 10 | RUN go mod download 11 | 12 | # Add sources 13 | COPY . . 14 | 15 | RUN go build -o out/auth0-go-web-app . 16 | 17 | # Expose port 3000 for our web app binary 18 | EXPOSE 3000 19 | 20 | CMD ["/01-Login/out/auth0-go-web-app"] 21 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | name: Semgrep 2 | 3 | on: 4 | pull_request: {} 5 | 6 | push: 7 | branches: ["master", "main"] 8 | 9 | schedule: 10 | - cron: '30 0 1,15 * *' 11 | 12 | jobs: 13 | semgrep: 14 | name: Scan 15 | runs-on: ubuntu-latest 16 | container: 17 | image: returntocorp/semgrep 18 | # Skip any PR created by dependabot to avoid permission issues 19 | if: (github.actor != 'dependabot[bot]') 20 | steps: 21 | - uses: actions/checkout@v3 22 | 23 | - run: semgrep ci 24 | env: 25 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} 26 | -------------------------------------------------------------------------------- /01-Login/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | 7 | "github.com/joho/godotenv" 8 | 9 | "01-Login/platform/authenticator" 10 | "01-Login/platform/router" 11 | ) 12 | 13 | func main() { 14 | if err := godotenv.Load(); err != nil { 15 | log.Fatalf("Failed to load the env vars: %v", err) 16 | } 17 | 18 | auth, err := authenticator.New() 19 | if err != nil { 20 | log.Fatalf("Failed to initialize the authenticator: %v", err) 21 | } 22 | 23 | rtr := router.New(auth) 24 | 25 | log.Print("Server listening on http://localhost:3000/") 26 | if err := http.ListenAndServe("0.0.0.0:3000", rtr); err != nil { 27 | log.Fatalf("There was an error with the http server: %v", err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /01-Login/web/app/logout/logout.go: -------------------------------------------------------------------------------- 1 | package logout 2 | 3 | import ( 4 | "net/http" 5 | "net/url" 6 | "os" 7 | 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | // Handler for our logout. 12 | func Handler(ctx *gin.Context) { 13 | logoutUrl, err := url.Parse("https://" + os.Getenv("AUTH0_DOMAIN") + "/v2/logout") 14 | if err != nil { 15 | ctx.String(http.StatusInternalServerError, err.Error()) 16 | return 17 | } 18 | 19 | scheme := "http" 20 | if ctx.Request.TLS != nil { 21 | scheme = "https" 22 | } 23 | 24 | returnTo, err := url.Parse(scheme + "://" + ctx.Request.Host) 25 | if err != nil { 26 | ctx.String(http.StatusInternalServerError, err.Error()) 27 | return 28 | } 29 | 30 | parameters := url.Values{} 31 | parameters.Add("returnTo", returnTo.String()) 32 | parameters.Add("client_id", os.Getenv("AUTH0_CLIENT_ID")) 33 | logoutUrl.RawQuery = parameters.Encode() 34 | 35 | ctx.Redirect(http.StatusTemporaryRedirect, logoutUrl.String()) 36 | } 37 | -------------------------------------------------------------------------------- /01-Login/web/template/home.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
18 | Zero friction identity infrastructure, built for developers
20 | SignIn 21 |