Title: IllegalArgumentException from 401 responses · Issue #1078 · scribejava/scribejava · GitHub
Open Graph Title: IllegalArgumentException from 401 responses · Issue #1078 · scribejava/scribejava
X Title: IllegalArgumentException from 401 responses · Issue #1078 · scribejava/scribejava
Description: Hi! I recently encountered a problem which seems to be somehow related to #492 It seems that the OAuth request behaves differently depending on whether the REST client is running locally or in a docker container in a cloud environment. F...
Open Graph Description: Hi! I recently encountered a problem which seems to be somehow related to #492 It seems that the OAuth request behaves differently depending on whether the REST client is running locally or in a do...
X Description: Hi! I recently encountered a problem which seems to be somehow related to #492 It seems that the OAuth request behaves differently depending on whether the REST client is running locally or in a do...
Opengraph URL: https://github.com/scribejava/scribejava/issues/1078
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IllegalArgumentException from 401 responses","articleBody":"Hi!\r\n\r\nI recently encountered a problem which seems to be somehow related to #492\r\n\r\nIt seems that the OAuth request behaves differently depending on whether the REST client is running locally or in a docker container in a cloud environment.\r\nFor the first case, when we use a wrong clientId for authentication, a 401 response with a body is received, which is logged in debug mode (in method `OAuth20Service.sendAccessTokenRequestSync()`) like follows:\r\n```\r\ncreated access token client credentials grant request with body params [grant_type=client_credentials], query string params []\r\nsend request for access token synchronously to https://...\r\nresponse status code: 401\r\nresponse body: {\"error\":\"unauthorized\",\"error_description\":\"Full authentication is required to access this resource\"}\r\n```\r\n\r\nI have absolutely no idea where the \"response body\" is taken from because it is 100% sure that the service doesn't send a body for a 401 response - it is simply empty (tested with curl, postman etc.)\r\n\r\nNow, when our client is running in the cloud (and contacting the exact same service), the response is null:\r\n```\r\ncreated access token client credentials grant request with body params [grant_type=client_credentials], query string params []\r\nsend request for access token synchronously to https://...\r\nresponse status code: 401\r\nresponse body: null\r\n```\r\n\r\nIn this case, an exception is thrown in `OAuth2AccessTokenJsonExtractor.extract()`:\r\n```\r\n java.lang.IllegalArgumentException: Response body is incorrect. Can't extract a token from an empty string\r\n\tat com.github.scribejava.core.utils.Preconditions.check(Preconditions.java:49)\r\n\tat com.github.scribejava.core.utils.Preconditions.checkEmptyString(Preconditions.java:31)\r\n\tat com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:34)\r\n\tat com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:17)\r\n\tat com.github.scribejava.core.oauth.OAuth20Service.sendAccessTokenRequestSync(OAuth20Service.java:157)\r\n\tat com.github.scribejava.core.oauth.OAuth20Service.getAccessTokenClientCredentialsGrant(OAuth20Service.java:418)\r\n```\r\n\r\nBecause of that, I am wondering: Why should it be a problem if there is no response body when we receive a 401 response? Actually, according to the HTTP code it is clear that there won't be an OAuth token and there will be nothing that could be extracted from the response. Besides this, the `generateError()` method which would be called afterwards does also allow the variables errorUri, errorCode and errorDescription to be null when throwing the `OAuth2AccessTokenErrorResponse` exception.\r\n\r\nThus, I think that the check for an empty string might be too early und should be placed below the if-statement, isn't it?\r\nThanks!","author":{"url":"https://github.com/Steinbam","@type":"Person","name":"Steinbam"},"datePublished":"2024-12-13T15:03:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1078/scribejava/issues/1078"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e774fc3f-022a-0c6d-2d0b-4c9628354767 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8876:13F113:5CB119B:7E44339:6973784A |
| html-safe-nonce | e488755d12afd4160087de8441c40232256d5fa629a736edc9901578ce49dad2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODc2OjEzRjExMzo1Q0IxMTlCOjdFNDQzMzk6Njk3Mzc4NEEiLCJ2aXNpdG9yX2lkIjoiMzUzODgyNDQzNjg1ODk3NjMzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2c0b52ec85b320f5a314dc18c72c5dc014e42fbcfcbe9af95b9c332830844a21 |
| hovercard-subject-tag | issue:2738598705 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/scribejava/scribejava/1078/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ec6287eafb87c2a7001f3b8a5f11660d9517360aa9bfc7c8f75e6bfd537d3958/scribejava/scribejava/issues/1078 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ec6287eafb87c2a7001f3b8a5f11660d9517360aa9bfc7c8f75e6bfd537d3958/scribejava/scribejava/issues/1078 |
| og:image:alt | Hi! I recently encountered a problem which seems to be somehow related to #492 It seems that the OAuth request behaves differently depending on whether the REST client is running locally or in a do... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Steinbam |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4cf879a11b0a28a85543899a36aaee9ec9ca2fb7bedad86c0da5731193c95f01 |
| turbo-cache-control | no-preview |
| go-import | github.com/scribejava/scribejava git https://github.com/scribejava/scribejava.git |
| octolytics-dimension-user_id | 15140551 |
| octolytics-dimension-user_login | scribejava |
| octolytics-dimension-repository_id | 889932 |
| octolytics-dimension-repository_nwo | scribejava/scribejava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 889932 |
| octolytics-dimension-repository_network_root_nwo | scribejava/scribejava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fe8be790582ef7a55477ce1918ac0ed16b106d31 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width