@@ -72,6 +72,48 @@ def login_handler():
7272 )
7373
7474
75+ @login .route ("/login2" , methods = ["GET" , "POST" ])
76+ @csrf .exempt
77+ @open_id .loginhandler
78+ def login2_handler ():
79+ if authentication .is_authenticated (flask .session ):
80+ return flask .redirect (open_id .get_next_url ())
81+
82+ try :
83+ root = authentication .request_macaroon ()
84+ except ApiResponseError as api_response_error :
85+ if api_response_error .status_code == 401 :
86+ return flask .redirect (flask .url_for (".logout" ))
87+ else :
88+ return flask .abort (502 , str (api_response_error ))
89+
90+ openid_macaroon = MacaroonRequest (
91+ caveat_id = authentication .get_caveat_id (root )
92+ )
93+ flask .session ["macaroon_root" ] = root
94+
95+ lp_teams = TeamsRequest (query_membership = [LP_CANONICAL_TEAM ])
96+
97+ response = open_id .try_login (
98+ "https://login.ubuntu.com" ,
99+ ask_for = ["email" , "nickname" , "image" ],
100+ ask_for_optional = ["fullname" ],
101+ extensions = [openid_macaroon , lp_teams ],
102+ )
103+
104+ location = response .headers ['Location' ]
105+
106+ return f"""
107+ <h1>/login2</h1>
108+ <p>root:{ root } </p>
109+ <p>caveat_id:{ authentication .get_caveat_id (root )} </p>
110+ <p>login base url:{ LOGIN_URL } </p>
111+ <p>openid_macaroon:{ openid_macaroon } </p>
112+ <p>lp_teams:{ lp_teams } </p>
113+ <p>location:{ location } </p>
114+ """
115+
116+
75117@open_id .after_login
76118def after_login (resp ):
77119 flask .session ["macaroon_discharge" ] = resp .extensions ["macaroon" ].discharge
0 commit comments