fixed api calls
This commit is contained in:
parent
8874df02d2
commit
69df101cb8
2 changed files with 28 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -209,6 +210,12 @@ func (c *Context) Form(name string) string {
|
||||||
return c.Request.PostFormValue(name)
|
return c.Request.PostFormValue(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) Query(name string) string {
|
||||||
|
// does nothing if called twice
|
||||||
|
c.Request.ParseForm()
|
||||||
|
return c.Request.Form.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) Var(name string) (ret string) {
|
func (c *Context) Var(name string) (ret string) {
|
||||||
ret = mux.Vars(c.Request)[name]
|
ret = mux.Vars(c.Request)[name]
|
||||||
return
|
return
|
||||||
|
|
@ -324,9 +331,9 @@ func (c *Context) ApproveLogin(user, challenge string) (rdr string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ApproveConsent(challenge string) (rdr string, err error) {
|
func (c *Context) ApproveConsent(challenge string) (rdr string, err error) {
|
||||||
req := c.Srv.API.AdminApi.AcceptConsentRequest(context.Background())
|
req := c.Srv.API.AdminApi.AcceptConsentRequest(context.Background()).
|
||||||
req.AcceptConsentRequest(*client.NewAcceptConsentRequest())
|
AcceptConsentRequest(*client.NewAcceptConsentRequest()).
|
||||||
req.ConsentChallenge(challenge)
|
ConsentChallenge(challenge)
|
||||||
_, resp, err := req.Execute()
|
_, resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -346,9 +353,9 @@ func (c *Context) ApproveConsent(challenge string) (rdr string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) RejectConsent(challenge string) (rdr string, err error) {
|
func (c *Context) RejectConsent(challenge string) (rdr string, err error) {
|
||||||
req := c.Srv.API.AdminApi.RejectConsentRequest(context.Background())
|
req := c.Srv.API.AdminApi.RejectConsentRequest(context.Background()).
|
||||||
req.RejectRequest(*client.NewRejectRequest())
|
RejectRequest(*client.NewRejectRequest()).
|
||||||
req.ConsentChallenge(challenge)
|
ConsentChallenge(challenge)
|
||||||
_, resp, err := req.Execute()
|
_, resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -368,10 +375,12 @@ func (c *Context) RejectConsent(challenge string) (rdr string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Consent(challenge string) (ci *consentInfo, err error) {
|
func (c *Context) Consent(challenge string) (ci *consentInfo, err error) {
|
||||||
req := c.Srv.API.AdminApi.GetConsentRequest(context.Background())
|
fmt.Println(challenge)
|
||||||
req.ConsentChallenge(challenge)
|
req := c.Srv.API.AdminApi.GetConsentRequest(context.Background()).
|
||||||
|
ConsentChallenge(challenge)
|
||||||
_, resp, err := req.Execute()
|
_, resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func loginHandler(ctx *Context) {
|
||||||
data loginData
|
data loginData
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
data.LoginChallenge = ctx.Var("login_challenge")
|
data.LoginChallenge = ctx.Query("login_challenge")
|
||||||
ctx.Template("loginHandler")
|
ctx.Template("loginHandler")
|
||||||
ctx.Data = webData{
|
ctx.Data = webData{
|
||||||
Title: "Login",
|
Title: "Login",
|
||||||
|
|
@ -198,7 +198,7 @@ func loginTotpHandler(ctx *Context) {
|
||||||
var data loginData
|
var data loginData
|
||||||
switch ctx.Method() {
|
switch ctx.Method() {
|
||||||
case "GET":
|
case "GET":
|
||||||
data.LoginChallenge = ctx.Var("login_challenge")
|
data.LoginChallenge = ctx.Query("login_challenge")
|
||||||
ctx.Data.Data = data
|
ctx.Data.Data = data
|
||||||
ctx.Exec()
|
ctx.Exec()
|
||||||
case "POST":
|
case "POST":
|
||||||
|
|
@ -227,6 +227,8 @@ func loginTotpHandler(ctx *Context) {
|
||||||
rdr, err = ctx.ApproveLogin(user, data.LoginChallenge)
|
rdr, err = ctx.ApproveLogin(user, data.LoginChallenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
|
ctx.log.Error(err, "error approving login")
|
||||||
|
ctx.Error("error approving login")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,11 +245,12 @@ func consentHandler(ctx *Context) {
|
||||||
var data consentData
|
var data consentData
|
||||||
switch ctx.Method() {
|
switch ctx.Method() {
|
||||||
case "GET":
|
case "GET":
|
||||||
data.ConsentChallenge = ctx.Var("consent_challenge")
|
data.ConsentChallenge = ctx.Query("consent_challenge")
|
||||||
ctx.Data.Data = data
|
ctx.Data.Data = data
|
||||||
ci, err := ctx.Consent(data.ConsentChallenge)
|
ci, err := ctx.Consent(data.ConsentChallenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.log.Error(err, "error getting consent info")
|
||||||
|
ctx.Error("error getting consent info")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data.Info = ci
|
data.Info = ci
|
||||||
|
|
@ -266,13 +269,15 @@ func consentHandler(ctx *Context) {
|
||||||
if consent == "approve" {
|
if consent == "approve" {
|
||||||
rdr, err = ctx.ApproveConsent(data.ConsentChallenge)
|
rdr, err = ctx.ApproveConsent(data.ConsentChallenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.log.Error(err, "error approving consent")
|
||||||
|
ctx.Error("error approving consent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rdr, err = ctx.RejectConsent(data.ConsentChallenge)
|
rdr, err = ctx.RejectConsent(data.ConsentChallenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.log.Error(err, "error rejecting consent")
|
||||||
|
ctx.Error("error rejecting consent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue