Use a fake context when running scope auth queries
This commit is contained in:
parent
0e4557bdd3
commit
8a41cc8a08
2 changed files with 30 additions and 6 deletions
|
@ -97,9 +97,21 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
ctx := c.Context()
|
ctx := c.Context()
|
||||||
|
|
||||||
|
// Create a temporary context.
|
||||||
|
|
||||||
|
t := fibre.NewContext(
|
||||||
|
c.Request(),
|
||||||
|
c.Response(),
|
||||||
|
c.Fibre(),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ensure we copy the session od.
|
||||||
|
|
||||||
|
t.Set(varKeyUniq, c.Get(varKeyUniq))
|
||||||
|
|
||||||
// Give full permissions to scope.
|
// Give full permissions to scope.
|
||||||
|
|
||||||
c.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB})
|
t.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB})
|
||||||
|
|
||||||
// Specify fields to show in logs.
|
// Specify fields to show in logs.
|
||||||
|
|
||||||
|
@ -125,7 +137,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
// If the query fails then return a 501 error.
|
// If the query fails then return a 501 error.
|
||||||
|
|
||||||
if res, err = db.Process(c, query, vars); err != nil {
|
if res, err = db.Process(t, query, vars); err != nil {
|
||||||
m := "Authentication scope signin was unsuccessful: Query failed"
|
m := "Authentication scope signin was unsuccessful: Query failed"
|
||||||
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
||||||
}
|
}
|
||||||
|
@ -199,7 +211,7 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
// If the query fails then return a 501 error.
|
// If the query fails then return a 501 error.
|
||||||
|
|
||||||
if res, err = db.Process(c, query, qvars); err != nil {
|
if res, err = db.Process(t, query, qvars); err != nil {
|
||||||
m := "Authentication scope signin was unsuccessful: `ON SIGNIN` failed:" + err.Error()
|
m := "Authentication scope signin was unsuccessful: `ON SIGNIN` failed:" + err.Error()
|
||||||
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,9 +96,21 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
ctx := c.Context()
|
ctx := c.Context()
|
||||||
|
|
||||||
|
// Create a temporary context.
|
||||||
|
|
||||||
|
t := fibre.NewContext(
|
||||||
|
c.Request(),
|
||||||
|
c.Response(),
|
||||||
|
c.Fibre(),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ensure we copy the session od.
|
||||||
|
|
||||||
|
t.Set(varKeyUniq, c.Get(varKeyUniq))
|
||||||
|
|
||||||
// Give full permissions to scope.
|
// Give full permissions to scope.
|
||||||
|
|
||||||
c.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB})
|
t.Set(varKeyAuth, &cnf.Auth{Kind: cnf.AuthDB})
|
||||||
|
|
||||||
// Specify fields to show in logs.
|
// Specify fields to show in logs.
|
||||||
|
|
||||||
|
@ -124,7 +136,7 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
// If the query fails then return a 501 error.
|
// If the query fails then return a 501 error.
|
||||||
|
|
||||||
if res, err = db.Process(c, query, vars); err != nil {
|
if res, err = db.Process(t, query, vars); err != nil {
|
||||||
m := "Authentication scope signup was unsuccessful: Query failed"
|
m := "Authentication scope signup was unsuccessful: Query failed"
|
||||||
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +210,7 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
||||||
|
|
||||||
// If the query fails then return a 501 error.
|
// If the query fails then return a 501 error.
|
||||||
|
|
||||||
if res, err = db.Process(c, query, qvars); err != nil {
|
if res, err = db.Process(t, query, qvars); err != nil {
|
||||||
m := "Authentication scope signup was unsuccessful: `ON SIGNUP` failed:" + err.Error()
|
m := "Authentication scope signup was unsuccessful: `ON SIGNUP` failed:" + err.Error()
|
||||||
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
return str, fibre.NewHTTPError(501).WithFields(f).WithMessage(m)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue