oauth_callback.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package router
  2. import (
  3. "github.com/go-chi/chi"
  4. "github.com/porter-dev/porter/api/server/handlers/oauth_callback"
  5. "github.com/porter-dev/porter/api/server/shared"
  6. "github.com/porter-dev/porter/api/server/shared/config"
  7. "github.com/porter-dev/porter/api/types"
  8. )
  9. func NewOAuthCallbackRegisterer(children ...*Registerer) *Registerer {
  10. return &Registerer{
  11. GetRoutes: GetOAuthCallbackRoutes,
  12. Children: children,
  13. }
  14. }
  15. func GetOAuthCallbackRoutes(
  16. r chi.Router,
  17. config *config.Config,
  18. basePath *types.Path,
  19. factory shared.APIEndpointFactory,
  20. children ...*Registerer,
  21. ) []*Route {
  22. relPath := "/oauth"
  23. routes := make([]*Route, 0)
  24. // GET /api/oauth/slack/callback -> oauth_callback.NewOAuthCallbackSlackHandler
  25. slackEndpoint := factory.NewAPIEndpoint(
  26. &types.APIRequestMetadata{
  27. Verb: types.APIVerbGet,
  28. Method: types.HTTPVerbGet,
  29. Path: &types.Path{
  30. Parent: basePath,
  31. RelativePath: relPath + "/slack/callback",
  32. },
  33. },
  34. )
  35. slackHandler := oauth_callback.NewOAuthCallbackSlackHandler(
  36. config,
  37. factory.GetDecoderValidator(),
  38. factory.GetResultWriter(),
  39. )
  40. routes = append(routes, &Route{
  41. Endpoint: slackEndpoint,
  42. Handler: slackHandler,
  43. Router: r,
  44. })
  45. // GET /api/oauth/digitalocean/callback -> oauth_callback.NewOAuthCallbackDOHandler
  46. doEndpoint := factory.NewAPIEndpoint(
  47. &types.APIRequestMetadata{
  48. Verb: types.APIVerbGet,
  49. Method: types.HTTPVerbGet,
  50. Path: &types.Path{
  51. Parent: basePath,
  52. RelativePath: relPath + "/digitalocean/callback",
  53. },
  54. },
  55. )
  56. doHandler := oauth_callback.NewOAuthCallbackDOHandler(
  57. config,
  58. factory.GetDecoderValidator(),
  59. factory.GetResultWriter(),
  60. )
  61. routes = append(routes, &Route{
  62. Endpoint: doEndpoint,
  63. Handler: doHandler,
  64. Router: r,
  65. })
  66. return routes
  67. }