MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / AppHandler

Method AppHandler

internal/http_handlers/app.go:21–78  ·  view source on GitHub ↗

AppHandler is the handler for the /app route

()

Source from the content-addressed store, hash-verified

19
20// AppHandler is the handler for the /app route
21func (h *httpProvider) AppHandler() gin.HandlerFunc {
22 log := h.Log.With().Str("func", "AppHandler").Logger()
23 return func(c *gin.Context) {
24 hostname := parsers.GetHost(c)
25 if !h.Config.EnableLoginPage {
26 log.Debug().Msg("Login page is disabled")
27 c.JSON(400, gin.H{"error": "login page is not enabled"})
28 return
29 }
30
31 redirectURI := strings.TrimSpace(c.Query("redirect_uri"))
32 state := strings.TrimSpace(c.Query("state"))
33 scopeString := strings.TrimSpace(c.Query("scope"))
34
35 var scope []string
36 if scopeString == "" {
37 scope = []string{"openid", "profile", "email"}
38 } else {
39 scope = strings.Split(scopeString, " ")
40 }
41
42 if redirectURI == "" {
43 redirectURI = hostname + "/app"
44 } else {
45 // validate redirect url with allowed origins
46 if !validators.IsValidRedirectURI(redirectURI, h.Config.AllowedOrigins, hostname) {
47 log.Debug().Msg("Invalid redirect url")
48 c.JSON(400, gin.H{"error": "invalid redirect url"})
49 return
50 }
51 }
52
53 // debug the request state
54 if pusher := c.Writer.Pusher(); pusher != nil {
55 // use pusher.Push() to do server push
56 if err := pusher.Push("/app/build/bundle.js", nil); err != nil {
57 log.Debug().Err(err).Msg("Failed to push bundle.js")
58 }
59 }
60
61 orgName := h.Config.OrganizationName
62 orgLogo := h.Config.OrganizationLogo
63 // Always revalidate the SPA shell so cached pointers to obsolete
64 // content-hashed chunks don't survive a deploy.
65 c.Header("Cache-Control", "no-cache, must-revalidate")
66 c.HTML(http.StatusOK, "app.tmpl", gin.H{
67 "data": map[string]interface{}{
68 "authorizerURL": hostname,
69 "redirectURL": redirectURI,
70 "scope": strings.Join(scope, " "),
71 "state": state,
72 "organizationName": orgName,
73 "organizationLogo": orgLogo,
74 "clientId": h.Config.ClientID,
75 },
76 })
77 }
78}

Callers

nothing calls this directly

Calls 3

GetHostFunction · 0.92
IsValidRedirectURIFunction · 0.92
QueryMethod · 0.65

Tested by

no test coverage detected