@@ -143,13 +143,6 @@ pub fn kth_auth(
143143}
144144
145145pub fn get_client ( ) -> Result < CoreClient > {
146- // "https://login.ug.kth.se/adfs/.well-known/openid-configuration".to_string(),
147- // println!(
148- // "metadata: {:?}",
149- // &IssuerUrl::new(
150- // "https://login.ug.kth.se/adfs/.well-known/openid-configuration".to_string(),
151- // )?
152- // );
153146 let provider_metadata = CoreProviderMetadata :: discover (
154147 & IssuerUrl :: new ( "https://login.ug.kth.se/adfs" . to_string ( ) ) ?,
155148 http_client,
@@ -172,7 +165,6 @@ pub fn get_client() -> Result<CoreClient> {
172165}
173166
174167pub fn use_oidc ( mut cookies : Cookies ) -> Result < Redirect > {
175- println ! ( "generating redirect" ) ;
176168 let client = get_client ( ) ?;
177169
178170 // Generate the full authorization URL.
@@ -183,26 +175,21 @@ pub fn use_oidc(mut cookies: Cookies) -> Result<Redirect> {
183175 Nonce :: new_random,
184176 )
185177 // Set the desired scopes.
186- // .add_scope(Scope::new("openid ".to_string()))
178+ . add_scope ( Scope :: new ( "kthid " . to_string ( ) ) )
187179 . url ( ) ;
188180
189- // This is the URL you should redirect the user to, in order to trigger the authorization
190- // process.
191-
192181 cookies. add ( Cookie :: new ( "nonce" , nonce. secret ( ) . clone ( ) ) ) ;
193- println ! ( "wrote nonce: {:?}" , nonce. secret( ) ) ;
182+ // println!("wrote nonce: {:?}", nonce.secret());
194183 Ok ( Redirect :: to ( auth_url. to_string ( ) ) )
195184}
196185
197186pub fn get_oidc_user ( params : Form < Code > , nonce : Nonce ) -> Result < ( ) > {
198- println ! ( "got nonce: {:?}" , nonce. secret( ) ) ;
187+ // println!("got nonce: {:?}", nonce.secret());
199188 let client = get_client ( ) ?;
200- println ! ( "getting oidc_user" ) ;
201189 let code = params
202190 . code
203191 . as_ref ( )
204192 . ok_or_else ( || anyhow ! ( "got no code in request" ) ) ?;
205- println ! ( "code: {}" , code) ;
206193 // Once the user has been redirected to the redirect URL, you'll have access to the
207194 // authorization code. For security reasons, your code should verify that the `state`
208195 // parameter returned by the server matches `csrf_state`.
@@ -212,7 +199,6 @@ pub fn get_oidc_user(params: Form<Code>, nonce: Nonce) -> Result<()> {
212199 . exchange_code ( AuthorizationCode :: new ( code. to_string ( ) ) )
213200 . request ( http_client) ?;
214201
215- println ! ( "Got token response" ) ;
216202 // Extract the ID token claims after verifying its authenticity and nonce.
217203 let id_token = token_response
218204 . id_token ( )
@@ -247,12 +233,13 @@ pub fn get_oidc_user(params: Form<Code>, nonce: Nonce) -> Result<()> {
247233 // The user_info request uses the AccessToken returned in the token response. To parse custom
248234 // claims, use UserInfoClaims directly (with the desired type parameters) rather than using the
249235 // CoreUserInfoClaims type alias.
250- let _userinfo : CoreUserInfoClaims = client
236+ let userinfo : CoreUserInfoClaims = client
251237 . user_info ( token_response. access_token ( ) . to_owned ( ) , None )
252238 . map_err ( |err| anyhow ! ( "No user info endpoint: {:?}" , err) ) ?
253239 . request ( http_client)
254240 . map_err ( |err| anyhow ! ( "Failed requesting user info: {:?}" , err) ) ?;
255241
242+ println ! ( "user info: {:?}" , userinfo) ;
256243 // See the OAuth2TokenResponse trait for a listing of other available fields such as
257244 // access_token() and refresh_token().
258245 Ok ( ( ) )
0 commit comments