@@ -30,7 +30,7 @@ use tracing::trace;
30
30
use vodozemac:: ecies:: CheckCode ;
31
31
32
32
use super :: {
33
- messages:: LoginFailureReason , oidc_client :: OidcClient , DeviceAuhorizationOidcError ,
33
+ messages:: LoginFailureReason , oauth_client :: OauthClient , DeviceAuthorizationOauthError ,
34
34
SecureChannelError ,
35
35
} ;
36
36
#[ cfg( doc) ]
@@ -66,11 +66,13 @@ pub enum LoginProgress {
66
66
/// The check code we need to, out of band, send to the other device.
67
67
check_code : CheckCode ,
68
68
} ,
69
- /// We're waiting for the OIDC provider to give us the access token. This
70
- /// will only happen if the other device allows the OIDC provider to so.
69
+ /// We're waiting for the OAuth 2.0 authorization server to give us the
70
+ /// access token. This will only happen if the other device allows the
71
+ /// OAuth 2.0 authorization server to do so.
71
72
WaitingForToken {
72
- /// The user code the OIDC provider has given us, the OIDC provider
73
- /// might ask the other device to enter this code.
73
+ /// The user code the OAuth 2.0 authorization server has given us, the
74
+ /// OAuth 2.0 authorization server might ask the other device to
75
+ /// enter this code.
74
76
user_code : String ,
75
77
} ,
76
78
/// The login process has completed.
@@ -115,20 +117,20 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
115
117
let check_code = channel. check_code ( ) . to_owned ( ) ;
116
118
self . state . set ( LoginProgress :: EstablishingSecureChannel { check_code } ) ;
117
119
118
- // Register the client with the OIDC provider .
119
- trace ! ( "Registering the client with the OIDC provider ." ) ;
120
- let oidc_client = self . register_client ( ) . await ?;
120
+ // Register the client with the OAuth 2.0 authorization server .
121
+ trace ! ( "Registering the client with the OAuth 2.0 authorization server ." ) ;
122
+ let oauth_client = self . register_client ( ) . await ?;
121
123
122
124
// We want to use the Curve25519 public key for the device ID, so let's generate
123
125
// a new vodozemac `Account` now.
124
126
let account = vodozemac:: olm:: Account :: new ( ) ;
125
127
let public_key = account. identity_keys ( ) . curve25519 ;
126
128
let device_id = public_key;
127
129
128
- // Let's tell the OIDC provider that we want to log in using the device
129
- // authorization grant described in [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628).
130
+ // Let's tell the OAuth 2.0 authorization server that we want to log in using
131
+ // the device authorization grant described in [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628).
130
132
trace ! ( "Requesting device authorization." ) ;
131
- let auth_grant_response = oidc_client . request_device_authorization ( device_id) . await ?;
133
+ let auth_grant_response = oauth_client . request_device_authorization ( device_id) . await ?;
132
134
133
135
// Now we need to inform the other device of the login protocols we picked and
134
136
// the URL they should use to log us in.
@@ -155,17 +157,17 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
155
157
}
156
158
}
157
159
158
- // The OIDC provider may or may not show this user code to double check that
159
- // we're talking to the right OIDC provider . Let us display this, so
160
+ // The OAuth 2.0 authorization server may or may not show this user code to
161
+ // double check that we're talking to the right server . Let us display this, so
160
162
// the other device can double check this as well.
161
163
let user_code = auth_grant_response. user_code ( ) ;
162
164
self . state
163
165
. set ( LoginProgress :: WaitingForToken { user_code : user_code. secret ( ) . to_owned ( ) } ) ;
164
166
165
- // Let's now wait for the access token to be provided to use by the OIDC
166
- // provider .
167
- trace ! ( "Waiting for the OIDC provider to give us the access token." ) ;
168
- let session_tokens = match oidc_client . wait_for_tokens ( & auth_grant_response) . await {
167
+ // Let's now wait for the access token to be provided to use by the OAuth 2.0
168
+ // authorization server .
169
+ trace ! ( "Waiting for the OAuth 2.0 authorization server to give us the access token." ) ;
170
+ let session_tokens = match oauth_client . wait_for_tokens ( & auth_grant_response) . await {
169
171
Ok ( t) => t,
170
172
Err ( e) => {
171
173
// If we received an error, and it's one of the ones we should report to the
@@ -192,11 +194,11 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
192
194
} ;
193
195
self . client . oidc ( ) . set_session_tokens ( session_tokens) ;
194
196
195
- // We only received an access token from the OIDC provider, we have no clue who
196
- // we are, so we need to figure out our user ID now.
197
- // TODO: This snippet is almost the same as the Oidc::finish_login_method(), why
198
- // is that method even a public method and not called as part of the set session
199
- // tokens method.
197
+ // We only received an access token from the OAuth 2.0 authorization server, we
198
+ // have no clue who we are, so we need to figure out our user ID
199
+ // now. TODO: This snippet is almost the same as the
200
+ // Oidc::finish_login_method(), why is that method even a public
201
+ // method and not called as part of the set session tokens method.
200
202
trace ! ( "Discovering our own user id." ) ;
201
203
let whoami_response =
202
204
self . client . whoami ( ) . await . map_err ( QRCodeLoginError :: UserIdDiscovery ) ?;
@@ -290,16 +292,17 @@ impl<'a> LoginWithQrCode<'a> {
290
292
Ok ( channel)
291
293
}
292
294
293
- async fn register_client ( & self ) -> Result < OidcClient , DeviceAuhorizationOidcError > {
295
+ async fn register_client ( & self ) -> Result < OauthClient , DeviceAuthorizationOauthError > {
294
296
let oidc = self . client . oidc ( ) ;
295
297
296
- // Let's figure out the OIDC issuer, this fetches the info from the homeserver.
298
+ // Let's figure out the OAuth 2.0 issuer, this fetches the info from the
299
+ // homeserver.
297
300
let issuer = oidc
298
301
. fetch_authentication_issuer ( )
299
302
. await
300
- . map_err ( DeviceAuhorizationOidcError :: AuthenticationIssuer ) ?;
303
+ . map_err ( DeviceAuthorizationOauthError :: AuthenticationIssuer ) ?;
301
304
302
- // Now we register the client with the OIDC provider .
305
+ // Now we register the client with the OAuth 2.0 authorization server .
303
306
let registration_response =
304
307
oidc. register_client ( & issuer, self . client_metadata . clone ( ) , None ) . await ?;
305
308
@@ -317,7 +320,7 @@ impl<'a> LoginWithQrCode<'a> {
317
320
let http_client = self . client . inner . http_client . clone ( ) ;
318
321
let server_metadata = oidc. provider_metadata ( ) . await ?;
319
322
320
- OidcClient :: new ( registration_response. client_id , & server_metadata, http_client)
323
+ OauthClient :: new ( registration_response. client_id , & server_metadata, http_client)
321
324
}
322
325
}
323
326
@@ -620,7 +623,10 @@ mod test {
620
623
alice. send_json ( message) . await . unwrap ( ) ;
621
624
}
622
625
623
- async fn mock_oidc_provider ( server : & MockServer , token_response : ResponseTemplate ) {
626
+ async fn mock_oauth_authorization_server (
627
+ server : & MockServer ,
628
+ token_response : ResponseTemplate ,
629
+ ) {
624
630
Mock :: given ( method ( "GET" ) )
625
631
. and ( path ( "/_matrix/client/unstable/org.matrix.msc2965/auth_issuer" ) )
626
632
. respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
@@ -680,7 +686,8 @@ mod test {
680
686
let rendezvous_server = MockedRendezvousServer :: new ( & server, "abcdEFG12345" ) . await ;
681
687
let ( sender, receiver) = tokio:: sync:: oneshot:: channel ( ) ;
682
688
683
- mock_oidc_provider ( & server, ResponseTemplate :: new ( 200 ) . set_body_json ( token ( ) ) ) . await ;
689
+ mock_oauth_authorization_server ( & server, ResponseTemplate :: new ( 200 ) . set_body_json ( token ( ) ) )
690
+ . await ;
684
691
685
692
Mock :: given ( method ( "GET" ) )
686
693
. and ( path ( "/_matrix/client/r0/account/whoami" ) )
@@ -775,7 +782,7 @@ mod test {
775
782
let rendezvous_server = MockedRendezvousServer :: new ( & server, "abcdEFG12345" ) . await ;
776
783
let ( sender, receiver) = tokio:: sync:: oneshot:: channel ( ) ;
777
784
778
- mock_oidc_provider ( & server, token_response) . await ;
785
+ mock_oauth_authorization_server ( & server, token_response) . await ;
779
786
780
787
Mock :: given ( method ( "GET" ) )
781
788
. and ( path ( "/_matrix/client/r0/account/whoami" ) )
@@ -841,7 +848,7 @@ mod test {
841
848
)
842
849
. await ;
843
850
844
- assert_let ! ( Err ( QRCodeLoginError :: Oidc ( e) ) = result) ;
851
+ assert_let ! ( Err ( QRCodeLoginError :: Oauth ( e) ) = result) ;
845
852
assert_eq ! (
846
853
e. as_request_token_error( ) ,
847
854
Some ( & DeviceCodeErrorResponseType :: AccessDenied ) ,
@@ -859,7 +866,7 @@ mod test {
859
866
)
860
867
. await ;
861
868
862
- assert_let ! ( Err ( QRCodeLoginError :: Oidc ( e) ) = result) ;
869
+ assert_let ! ( Err ( QRCodeLoginError :: Oauth ( e) ) = result) ;
863
870
assert_eq ! (
864
871
e. as_request_token_error( ) ,
865
872
Some ( & DeviceCodeErrorResponseType :: ExpiredToken ) ,
0 commit comments