move example/server/*.go to example/server/exampleop/
This commit is contained in:
parent
41cd9c735b
commit
1073af88c2
4 changed files with 46 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package exampleop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -12,8 +12,7 @@ const (
|
|||
queryAuthRequestID = "authRequestID"
|
||||
)
|
||||
|
||||
var (
|
||||
loginTmpl, _ = template.New("login").Parse(`
|
||||
var loginTmpl, _ = template.New("login").Parse(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -41,7 +40,6 @@ var (
|
|||
</form>
|
||||
</body>
|
||||
</html>`)
|
||||
)
|
||||
|
||||
type login struct {
|
||||
authenticate authenticate
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package exampleop
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -27,14 +27,15 @@ func init() {
|
|||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
type Storage interface {
|
||||
op.Storage
|
||||
CheckUsernamePassword(username, password, id string) error
|
||||
}
|
||||
|
||||
func SetupServer(ctx context.Context, port string, storage Storage) *mux.Router {
|
||||
// this will allow us to use an issuer with http:// instead of https://
|
||||
os.Setenv(op.OidcDevMode, "true")
|
||||
|
||||
port := "9998"
|
||||
|
||||
// the OpenID Provider requires a 32-byte key for (token) encryption
|
||||
// be sure to create a proper crypto random key and manage it securely!
|
||||
key := sha256.Sum256([]byte("test"))
|
||||
|
@ -49,11 +50,6 @@ func main() {
|
|||
}
|
||||
})
|
||||
|
||||
// the OpenIDProvider interface needs a Storage interface handling various checks and state manipulations
|
||||
// this might be the layer for accessing your database
|
||||
// in this example it will be handled in-memory
|
||||
storage := storage.NewStorage(storage.NewUserStore())
|
||||
|
||||
// creation of the OpenIDProvider with the just created in-memory Storage
|
||||
provider, err := newOP(ctx, storage, port, key)
|
||||
if err != nil {
|
||||
|
@ -75,15 +71,7 @@ func main() {
|
|||
// then you would have to set the path prefix (/custom/path/)
|
||||
router.PathPrefix("/").Handler(provider.HttpHandler())
|
||||
|
||||
server := &http.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: router,
|
||||
}
|
||||
err = server.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<-ctx.Done()
|
||||
return router
|
||||
}
|
||||
|
||||
// newOP will create an OpenID Provider for localhost on a specified port with a given encryption key
|
32
example/server/main.go
Normal file
32
example/server/main.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/zitadel/oidc/example/server/exampleop"
|
||||
"github.com/zitadel/oidc/example/server/storage"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// the OpenIDProvider interface needs a Storage interface handling various checks and state manipulations
|
||||
// this might be the layer for accessing your database
|
||||
// in this example it will be handled in-memory
|
||||
storage := storage.NewStorage(storage.NewUserStore())
|
||||
|
||||
port := "9998"
|
||||
router := exampleop.SetupServer(ctx, port, storage)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: router,
|
||||
}
|
||||
err := server.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
<-ctx.Done()
|
||||
}
|
|
@ -26,6 +26,9 @@ var serviceKey1 = &rsa.PublicKey{
|
|||
E: 65537,
|
||||
}
|
||||
|
||||
// var _ op.Storage = &storage{}
|
||||
// var _ op.ClientCredentialsStorage = &storage{}
|
||||
|
||||
// storage implements the op.Storage interface
|
||||
// typically you would implement this as a layer on top of your database
|
||||
// for simplicity this example keeps everything in-memory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue