1- import { Hono } from "hono" ;
1+ import { Hono } from 'hono'
2+
23import {
3- layout ,
44 homeContent ,
5+ layout ,
56 parseApproveFormBody ,
6- renderAuthorizationRejectedContent ,
77 renderAuthorizationApprovedContent ,
8+ renderAuthorizationRejectedContent ,
89 renderLoggedInAuthorizeScreen ,
910 renderLoggedOutAuthorizeScreen ,
10- } from "./utils" ;
11- import type { OAuthHelpers } from "@cloudflare/workers-oauth-provider" ;
11+ } from './utils'
12+
13+ import type { OAuthHelpers } from '@cloudflare/workers-oauth-provider'
1214
1315export type Bindings = Env & {
14- OAUTH_PROVIDER : OAuthHelpers ;
15- } ;
16+ OAUTH_PROVIDER : OAuthHelpers
17+ }
1618
1719const app = new Hono < {
18- Bindings : Bindings ;
19- } > ( ) ;
20+ Bindings : Bindings
21+ } > ( )
2022
2123// Render a basic homepage placeholder to make sure the app is up
22- app . get ( "/" , async ( c ) => {
23- const content = await homeContent ( c . req . raw ) ;
24- return c . html ( layout ( content , " MCP Remote Auth Demo - Home" ) ) ;
25- } ) ;
24+ app . get ( '/' , async ( c ) => {
25+ const content = await homeContent ( c . req . raw )
26+ return c . html ( layout ( content , ' MCP Remote Auth Demo - Home' ) )
27+ } )
2628
2729// Render an authorization page
2830// If the user is logged in, we'll show a form to approve the appropriate scopes
2931// If the user is not logged in, we'll show a form to both login and approve the scopes
30- app . get ( " /authorize" , async ( c ) => {
32+ app . get ( ' /authorize' , async ( c ) => {
3133 // We don't have an actual auth system, so to demonstrate both paths, you can
3234 // hard-code whether the user is logged in or not. We'll default to true
3335 // const isLoggedIn = false;
34- const isLoggedIn = true ;
36+ const isLoggedIn = true
3537
36- const oauthReqInfo = await c . env . OAUTH_PROVIDER . parseAuthRequest ( c . req . raw ) ;
38+ const oauthReqInfo = await c . env . OAUTH_PROVIDER . parseAuthRequest ( c . req . raw )
3739
3840 const oauthScopes = [
3941 {
40- name : " read_profile" ,
41- description : " Read your basic profile information" ,
42+ name : ' read_profile' ,
43+ description : ' Read your basic profile information' ,
4244 } ,
43- { name : " read_data" , description : " Access your stored data" } ,
44- { name : " write_data" , description : " Create and modify your data" } ,
45- ] ;
45+ { name : ' read_data' , description : ' Access your stored data' } ,
46+ { name : ' write_data' , description : ' Create and modify your data' } ,
47+ ]
4648
4749 if ( isLoggedIn ) {
48- const content = await renderLoggedInAuthorizeScreen ( oauthScopes , oauthReqInfo ) ;
49- return c . html ( layout ( content , " MCP Remote Auth Demo - Authorization" ) ) ;
50+ const content = await renderLoggedInAuthorizeScreen ( oauthScopes , oauthReqInfo )
51+ return c . html ( layout ( content , ' MCP Remote Auth Demo - Authorization' ) )
5052 }
5153
52- const content = await renderLoggedOutAuthorizeScreen ( oauthScopes , oauthReqInfo ) ;
53- return c . html ( layout ( content , " MCP Remote Auth Demo - Authorization" ) ) ;
54- } ) ;
54+ const content = await renderLoggedOutAuthorizeScreen ( oauthScopes , oauthReqInfo )
55+ return c . html ( layout ( content , ' MCP Remote Auth Demo - Authorization' ) )
56+ } )
5557
5658// The /authorize page has a form that will POST to /approve
5759// This endpoint is responsible for validating any login information and
5860// then completing the authorization request with the OAUTH_PROVIDER
59- app . post ( " /approve" , async ( c ) => {
61+ app . post ( ' /approve' , async ( c ) => {
6062 const { action, oauthReqInfo, email, password } = await parseApproveFormBody (
61- await c . req . parseBody ( ) ,
62- ) ;
63+ await c . req . parseBody ( )
64+ )
6365
6466 if ( ! oauthReqInfo ) {
65- return c . html ( " INVALID LOGIN" , 401 ) ;
67+ return c . html ( ' INVALID LOGIN' , 401 )
6668 }
6769
6870 // If the user needs to both login and approve, we should validate the login first
69- if ( action === " login_approve" ) {
71+ if ( action === ' login_approve' ) {
7072 // We'll allow any values for email and password for this demo
7173 // but you could validate them here
7274 // Ex:
@@ -75,10 +77,10 @@ app.post("/approve", async (c) => {
7577 if ( false ) {
7678 return c . html (
7779 layout (
78- await renderAuthorizationRejectedContent ( "/" ) ,
79- " MCP Remote Auth Demo - Authorization Status" ,
80- ) ,
81- ) ;
80+ await renderAuthorizationRejectedContent ( '/' ) ,
81+ ' MCP Remote Auth Demo - Authorization Status'
82+ )
83+ )
8284 }
8385 }
8486
@@ -88,20 +90,20 @@ app.post("/approve", async (c) => {
8890 request : oauthReqInfo ,
8991 userId : email ,
9092 metadata : {
91- label : " Test User" ,
93+ label : ' Test User' ,
9294 } ,
9395 scope : oauthReqInfo . scope ,
9496 props : {
9597 userEmail : email ,
9698 } ,
97- } ) ;
99+ } )
98100
99101 return c . html (
100102 layout (
101103 await renderAuthorizationApprovedContent ( redirectTo ) ,
102- " MCP Remote Auth Demo - Authorization Status" ,
103- ) ,
104- ) ;
105- } ) ;
104+ ' MCP Remote Auth Demo - Authorization Status'
105+ )
106+ )
107+ } )
106108
107- export default app ;
109+ export default app
0 commit comments