@@ -50,7 +50,25 @@ func contentHandler(content []byte, contentType string) func(w http.ResponseWrit
5050}
5151
5252func authHandler (w http.ResponseWriter , r * http.Request ) {
53- http .Redirect (w , r , oauth .OAuthUrl (), http .StatusFound )
53+ // Pass the app parameter to the OAuth state if present
54+ app := r .URL .Query ().Get ("app" )
55+ oauthURL := oauth .OAuthUrl ()
56+
57+ // If app parameter is present, add it to the state
58+ if app != "" {
59+ // Store app parameter in session or pass it through state
60+ // For now, we'll use a cookie to preserve it
61+ http .SetCookie (w , & http.Cookie {
62+ Name : "jprq_app" ,
63+ Value : app ,
64+ Path : "/" ,
65+ MaxAge : 300 , // 5 minutes
66+ HttpOnly : true ,
67+ SameSite : http .SameSiteLaxMode ,
68+ })
69+ }
70+
71+ http .Redirect (w , r , oauthURL , http .StatusFound )
5472}
5573
5674func oauthCallback (w http.ResponseWriter , r * http.Request ) {
@@ -64,6 +82,40 @@ func oauthCallback(w http.ResponseWriter, r *http.Request) {
6482 http .Redirect (w , r , "/auth" , http .StatusTemporaryRedirect )
6583 return
6684 }
85+
86+ // Check if this is an app-based authentication
87+ appCookie , err := r .Cookie ("jprq_app" )
88+ if err == nil && appCookie .Value != "" {
89+ // Clear the cookie
90+ http .SetCookie (w , & http.Cookie {
91+ Name : "jprq_app" ,
92+ Value : "" ,
93+ Path : "/" ,
94+ MaxAge : - 1 ,
95+ HttpOnly : true ,
96+ })
97+
98+ // Redirect to the app URL with the token
99+ var appURL string
100+ switch appCookie .Value {
101+ case "mac" :
102+ appURL = fmt .Sprintf ("jprq://auth/callback?token=%s" , token )
103+ case "windows" :
104+ appURL = fmt .Sprintf ("jprq://auth/callback?token=%s" , token )
105+ case "linux" :
106+ appURL = fmt .Sprintf ("jprq://auth/callback?token=%s" , token )
107+ default :
108+ // Unknown app type, fall back to web display
109+ w .Header ().Set ("Content-Type" , "text/html" )
110+ w .Write ([]byte (fmt .Sprintf (tokenHtml , token )))
111+ return
112+ }
113+
114+ http .Redirect (w , r , appURL , http .StatusFound )
115+ return
116+ }
117+
118+ // Default: show token in web page
67119 w .Header ().Set ("Content-Type" , "text/html" )
68120 w .Write ([]byte (fmt .Sprintf (tokenHtml , token )))
69121}
0 commit comments