Initial commit
This commit is contained in:
60
controllers/auth.go
Normal file
60
controllers/auth.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about auth
|
||||
type AuthController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create auths
|
||||
// @Param body body []models.auth true "The auth content"
|
||||
// @Success 200 {string} models.auth.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (o *AuthController) Post() {
|
||||
// store and return Id or post with UUID
|
||||
o.Data["json"] = map[string]string{"Id": "?"}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find auth by authid
|
||||
// @Param authId path string true "the authid you want to get"
|
||||
// @Success 200 {auth} models.auth
|
||||
// @Failure 403 :authId is empty
|
||||
// @router /:authId [get]
|
||||
func (o *AuthController) Get() {
|
||||
authId := o.Ctx.Input.Param(":authId")
|
||||
fmt.Println(authId)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Find
|
||||
// @Description find auths with query
|
||||
// @Param query path string true "the keywords you need"
|
||||
// @Success 200 {auths} []models.auth
|
||||
// @Failure 403
|
||||
// @router /find/:query [get]
|
||||
func (o *AuthController) Find() {
|
||||
query := o.Ctx.Input.Param(":query")
|
||||
fmt.Println(query)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the auth
|
||||
// @Param authId path string true "The authId you want to delete"
|
||||
// @Success 200 {string} delete success!
|
||||
// @Failure 403 authId is empty
|
||||
// @router /:authId [delete]
|
||||
func (o *AuthController) Delete() {
|
||||
authId := o.Ctx.Input.Param(":authId")
|
||||
fmt.Println(authId)
|
||||
o.ServeJSON()
|
||||
}
|
||||
52
controllers/registration.go
Normal file
52
controllers/registration.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"oc-auth/models"
|
||||
"strings"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
// Operations about auth
|
||||
type RegistrationController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create auths
|
||||
// @Param body body models.Application true "The app info"
|
||||
// @Success 200 {string} models.auth.Id
|
||||
// @Failure 403 body is empty
|
||||
// @router / [post]
|
||||
func (o *RegistrationController) Post() {
|
||||
var app models.Application
|
||||
// Store the app info in the nats server
|
||||
err := json.Unmarshal(o.Ctx.Input.RequestBody, &app)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
servers := []string{"nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"}
|
||||
|
||||
nc, err := nats.Connect(strings.Join(servers, ","))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
js, err := nc.JetStream(nats.PublishAsyncMaxPending(256))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
kv, err := js.KeyValue("auth")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
kv.Put(app.ClientId, o.Ctx.Input.RequestBody)
|
||||
// register to OIDC server
|
||||
|
||||
// store and return Id or post with UUID
|
||||
o.Data["json"] = map[string]string{"Id": "?"}
|
||||
o.ServeJSON()
|
||||
}
|
||||
19
controllers/version.go
Normal file
19
controllers/version.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// VersionController operations for Version
|
||||
type VersionController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description get version
|
||||
// @Success 200
|
||||
// @router / [get]
|
||||
func (c *VersionController) GetAll() {
|
||||
c.Data["json"] = map[string]string{"version": "1"}
|
||||
c.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user