@@ -36,10 +36,11 @@ const std::string AUTH_TYPE = "Basic";
3636}
3737
3838namespace Wt {
39- namespace Auth {
4039
4140LOGGER ("OAuthTokenEndpoint" );
4241
42+ namespace Auth {
43+
4344OAuthTokenEndpoint ::OAuthTokenEndpoint (AbstractUserDatabase & db ,
4445 std ::string issuer )
4546 : db_ (& db ),
@@ -115,6 +116,12 @@ void OAuthTokenEndpoint::handleRequest(const Http::Request &request, Http::Respo
115116 if (!code || clientId .empty () || clientSecret .empty () || !grantType || !redirectUri ) {
116117 response .setStatus (400 );
117118 response .out () << "{\"error\": \"invalid_request\"}" << std ::endl ;
119+ LOG_INFO ("{\"error\": \"invalid_request\"}:"
120+ << " code:" << (code ? * code : "NULL" )
121+ << " clientId: " << clientId
122+ << " clientSecret: " << (clientSecret .empty () ? "MISSING" : "NOT MISSING" )
123+ << " grantType: " << (grantType ? * grantType : "NULL" )
124+ << " redirectUri: " << (redirectUri ? * redirectUri : "NULL" ));
118125 return ;
119126 }
120127 OAuthClient client = db_ -> idpClientFindWithId (clientId );
@@ -129,18 +136,35 @@ void OAuthTokenEndpoint::handleRequest(const Http::Request &request, Http::Respo
129136 methodToString (client .authMethod ()));
130137 }
131138 response .out () << "{\n\"error\": \"invalid_client\"\n}" << std ::endl ;
139+ LOG_INFO ("{\"error\": \"invalid_client\"}: "
140+ << " id: " << clientId
141+ << " client: " << (client .checkValid () ? "valid" : "not valid" )
142+ << " secret: " << (client .verifySecret (clientSecret ) ? "correct" : "incorrect" )
143+ << " method: " << (client .authMethod () != authMethod ? "no match" : "match" )
144+ );
132145 return ;
133146 }
134147 if (* grantType != GRANT_TYPE ) {
135148 response .setStatus (400 );
136149 response .out () << "{\n\"error\": \"unsupported_grant_type\"\n}" << std ::endl ;
150+ LOG_INFO ("{\"error\": \"unsupported_grant_type\"}: "
151+ << " id: " << clientId
152+ << " grantType: " << grantType
153+ );
137154 return ;
138155 }
139156 IssuedToken authCode = db_ -> idpTokenFindWithValue (GRANT_TYPE , * code );
140157 if (!authCode .checkValid () || authCode .redirectUri () != * redirectUri
141158 || WDateTime ::currentDateTime () > authCode .expirationTime ()) {
142159 response .setStatus (400 );
143160 response .out () << "{\n\"error\": \"invalid_grant\"\n}" << std ::endl ;
161+ LOG_INFO ("{\"error\": \"invalid_grant\"}:"
162+ << " id: " << clientId
163+ << " code: " << * code
164+ << " authCode: " << (authCode .checkValid () ? "valid" : "not valid" )
165+ << " redirectUri: " << * redirectUri << (authCode .redirectUri () != * redirectUri ? " - invalid" : " - valid" )
166+ << " timestamp: " << authCode .expirationTime ().toString () << (WDateTime ::currentDateTime () > authCode .expirationTime () ? ", expired" : ", not expired" )
167+ );
144168 return ;
145169 }
146170 std ::string accessTokenValue = WRandom ::generateId ();
@@ -178,6 +202,9 @@ void OAuthTokenEndpoint::handleRequest(const Http::Request &request, Http::Respo
178202 root ["id_token" ] = Json ::Value (header + "." + payload + "." + signature );
179203 }
180204 response .out () << Json ::serialize (root );
205+
206+ LOG_INFO ("success: " << clientId << ", " << user .id () << ", " << db_ -> email (user ));
207+
181208#ifdef WT_TARGET_JAVA
182209 } catch (std ::io_exception ioe ) {
183210 LOG_ERROR (ioe .message ());
0 commit comments