mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Initial commit
This commit is contained in:
commit
c04107cf3d
6 changed files with 131 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
*.json
|
||||||
13
go.mod
Normal file
13
go.mod
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
module davidallendj/ochami-auth
|
||||||
|
|
||||||
|
go 1.21.5
|
||||||
|
|
||||||
|
require github.com/ory/client-go v1.6.1
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
|
golang.org/x/net v0.20.0 // indirect
|
||||||
|
golang.org/x/oauth2 v0.16.0 // indirect
|
||||||
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
|
)
|
||||||
26
go.sum
Normal file
26
go.sum
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/ory/client-go v1.6.1 h1:nVb1ZRtBQS9oLJQR7VK7t9cxNHXKdZ2CtpoDmmHOhAQ=
|
||||||
|
github.com/ory/client-go v1.6.1/go.mod h1:6dx0Ir6q8O9mUvl3sqrlyR+0LalXLwwKedVDDmSPNQs=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||||
|
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||||
|
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||||
|
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||||
|
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||||
|
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
|
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||||
|
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
28
handler.go
Normal file
28
handler.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (app *App) dashboardHandler() http.HandlerFunc {
|
||||||
|
return func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
tmpl, err := template.New("index.html").ParseFiles("index.html")
|
||||||
|
if err != nil {
|
||||||
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session, err := json.Marshal(getSession(request.Context()))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = tmpl.ExecuteTemplate(writer, "index.html", string(session))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
main.go
Normal file
35
main.go
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"davidallendj/ochami-auth/oidc"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
clientId = ""
|
||||||
|
redirectUri = ""
|
||||||
|
state = ""
|
||||||
|
response_type = "code"
|
||||||
|
userDB = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildAuthorizationUrl(authEndpoint string, clientId string, redirectUri []string, state string, responseType string, scope []string) string {
|
||||||
|
return authEndpoint + "?" + "cilent_id=" + clientId +
|
||||||
|
"&redirect_url=" + strings.Join(redirectUri, ",") +
|
||||||
|
"&response_type=" + responseType +
|
||||||
|
"&state=" + state +
|
||||||
|
"&scope=" + strings.Join(scope, "+")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
client := oidc.NewOpenIDConnect()
|
||||||
|
var authorizationUrl = buildAuthorizationUrl(
|
||||||
|
client.
|
||||||
|
)
|
||||||
|
var tokenUrl = loginHost + tokenEndpoint
|
||||||
|
// start a HTTP server to listen for callback responses
|
||||||
|
// extract code from response and exchange for bearer token
|
||||||
|
// extract ID token and save user info
|
||||||
|
// use ID token/user info to get access token from Hydra
|
||||||
|
}
|
||||||
28
oidc/oidc.go
Normal file
28
oidc/oidc.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package oidc
|
||||||
|
|
||||||
|
type OpenIDConnectProvider struct {
|
||||||
|
Host string
|
||||||
|
AuthorizeEndpoint string
|
||||||
|
TokenEndpoint string
|
||||||
|
ConfigEndpoint string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOpenIDConnect() *OpenIDConnectProvider {
|
||||||
|
return &OpenIDConnectProvider{
|
||||||
|
Host: "https://gitlab.newmexicoconsortium.org",
|
||||||
|
AuthorizeEndpoint: "/oauth/authorize",
|
||||||
|
TokenEndpoint: "/oauth/token",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (oidc *OpenIDConnectProvider) AuthorizeUrl() string {
|
||||||
|
return oidc.Host + oidc.AuthorizeEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (oidc *OpenIDConnectProvider) TokenUrl() string {
|
||||||
|
return oidc.Host + oidc.TokenEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (oidc *OpenIDConnectProvider) FetchServerConfiguration(url string) {
|
||||||
|
// make a request to a server's openid-configuration
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue