func (this FakeProvider) Middleware() rack.Middleware {
	if this.middleware == nil {
		hostcept := interceptor.New()
		hostcept.Intercept("/auth", rack.Func(func(vars map[string]interface{}, next func()) {
			values := url.Values{}
			values.Set("state", parser.V(vars).FormValue("state"))
			values.Set("code", "c0D3")
			redirecter.V(vars).Redirect(parser.V(vars).FormValue("redirect_uri") + "?" + values.Encode())
		}))
		hostcept.Intercept("/token", rack.Func(func(vars map[string]interface{}, next func()) {
			if parser.V(vars).FormValue("code") == "c0D3" {
				httper.V(vars).GetRequest().Header.Set("content-type", "application/json")
				httper.V(vars).SetMessageString("{\"access_token\":\"tokendata\",\"refresh_token\":\"refreshtoken1\",\"expires_in\":3600}")
			}
		}))
		hostcept.Intercept("/data", rack.Func(func(vars map[string]interface{}, next func()) {
			if auth := httper.V(vars).GetRequest().Header.Get("Authorization"); auth != "Bearer tokendata" {
				httper.V(vars).SetMessageString("Invalid authorization: " + auth)
			}
			httper.V(vars).SetMessageString("payload")
		}))
		hostrackup := rack.New()
		hostrackup.Add(sessioner.Middleware)
		hostrackup.Add(hostcept)

		this.middleware = hostrackup
	}
	return this.middleware
}
Beispiel #2
0
//New converts your Oauther into Middleware, and allows you to do something once you have the token
func New(o Oauther, t TokenHandler) rack.Middleware {
	i := interceptor.New()
	i.Intercept(o.StartUrl(), &codeGetter{o})
	i.Intercept(o.RedirectUrl(), &tokenGetter{o, t})
	return i
}