Skip to content

skiarn/oauth2Provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oauth2Provider

Example usage, create file oauthKeys.json.

example see, src/github.com/skiarn/auth2Provider/oauthKeys.json

package main
import(
  "net/http"
  "log"
  oauth "github.com/skiarn/oauth2Provider"
  "fmt"
)

const htmlIndex = `<html><body>Logged in with <a href="/auth/github">GitHub</a></body></html>`

func handleMain(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "text/html; charset=utf-8")
    w.WriteHeader(http.StatusOK)
    w.Write([]byte(htmlIndex))
}

func main() {
    var oauthConf *oauth.OauthConf
    oauthConf, err := oauth.ReadOauthConfFile("./oauthKeys.json")
    if err != nil {
      log.Fatal(err)
    }
    http.HandleFunc("/", handleMain)
    http.HandleFunc("/auth/github", oauthConf.HandleGitHubLogin)
    http.HandleFunc("/auth/github/callback", oauthConf.HandleGitHubCallback)
    fmt.Print("Started running on http://127.0.0.1:8080\n")
    fmt.Println(http.ListenAndServe(":8080", nil))
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages