oauth_callback.go 1.9 KB

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