// LoginHandler handles OAuth1 login requests by obtaining a request token and // secret (temporary credentials) and adding it to the ctx. If successful, // handling delegates to the success handler, otherwise to the failure handler. // // Typically, the success handler is an AuthRedirectHandler or a handler which // stores the request token secret. func LoginHandler(config *oauth1.Config, success, failure ctxh.ContextHandler) ctxh.ContextHandler { if failure == nil { failure = gologin.DefaultFailureHandler } fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) { requestToken, requestSecret, err := config.RequestToken() if err != nil { ctx = gologin.WithError(ctx, err) failure.ServeHTTP(ctx, w, req) return } ctx = WithRequestToken(ctx, requestToken, requestSecret) success.ServeHTTP(ctx, w, req) } return ctxh.ContextHandlerFunc(fn) }