Title: 401 when using ChunkedUploadProvider for large mail attachments · Issue #52 · microsoftgraph/msgraph-sdk-java-auth · GitHub
Open Graph Title: 401 when using ChunkedUploadProvider for large mail attachments · Issue #52 · microsoftgraph/msgraph-sdk-java-auth
X Title: 401 when using ChunkedUploadProvider for large mail attachments · Issue #52 · microsoftgraph/msgraph-sdk-java-auth
Description: Expected behavior ChunkedUploadProvider.upload(...) uploads the specified file and attaches it to the message, per https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java. Actual behavior 401 : Unauthorized upon reques...
Open Graph Description: Expected behavior ChunkedUploadProvider.upload(...) uploads the specified file and attaches it to the message, per https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java. Actual...
X Description: Expected behavior ChunkedUploadProvider.upload(...) uploads the specified file and attaches it to the message, per https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java. Actual...
Opengraph URL: https://github.com/microsoftgraph/msgraph-sdk-java-auth/issues/52
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"401 when using ChunkedUploadProvider for large mail attachments","articleBody":"Expected behavior\nChunkedUploadProvider.upload(...) uploads the specified file and attaches it to the message, per https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java.\nActual behavior\n401 : Unauthorized upon request.\ncom.microsoft.graph.core.ClientException: Error code: InvalidAudienceForResource\nError message: The audience claim value is invalid for current resource. Audience claim is 'https://graph.microsoft.com/', request url is 'https://outlook.office.com/api/v2.0/Users...'.\nThe issue appears to be the API is including an Authorization header in the request, in contradiction with the documentation.\n\nDo not specify an Authorization request header. The PUT query uses a pre-authenticated URL from the uploadUrl property, that allows access to the https://outlook.office.com domain.\n\nInspection of the authtoken parameter in the upload session's URL shows the correct audience ( \"aud\": \"https://outlook.office.com/api/\"), while the auth bearer token's audience is \"https://graph.microsoft.com\".\nSteps to reproduce the behavior\nUsing an MS Dev account and pregenerated users; microsoft-graph-1.9.0.jar, microsoft-graph-core.1.0.1.jar, microsoft-graph-auth-1.9.0.jar; Java 8.\npublic class LargeAttachmentUploadError implements GraphExampleConstants {\n\n public static void main(String[] args) throws IOException {\n String recipient = args[0];\n String filepath = args[1];\n Path p = Paths.get(new File(filepath).toURI());\n \n UsernamePasswordProvider authProvider = new UsernamePasswordProvider(\n clientID,\n Arrays.asList(\"https://graph.microsoft.com/.default\"),\n username,\n password,\n NationalCloud.Global,\n tenant,\n clientSecret);\n\n IGraphServiceClient graphClient = GraphServiceClient\n .builder()\n .authenticationProvider(authProvider)\n .buildClient();\n\n graphClient.getLogger().setLoggingLevel(LoggerLevel.DEBUG); \n \n Message message = new Message();\n message.subject = \"Meet for lunch?\";\n ItemBody body = new ItemBody();\n body.contentType = BodyType.TEXT;\n body.content = \"The new cafeteria is open.\";\n message.body = body;\n LinkedList\u003cRecipient> toRecipientsList = new LinkedList\u003cRecipient>();\n Recipient toRecipients = new Recipient();\n EmailAddress emailAddress = new EmailAddress();\n emailAddress.address = recipient; \n toRecipients.emailAddress = emailAddress;\n toRecipientsList.add(toRecipients);\n message.toRecipients = toRecipientsList;\n message.hasAttachments = true;\n message = graphClient.me().mailFolders(\"drafts\").messages().buildRequest().post(message);\n \n AttachmentItem attachmentItem = new AttachmentItem();\n attachmentItem.name = p.getFileName().toString(); \n attachmentItem.isInline = false;\n attachmentItem.attachmentType = AttachmentType.FILE; \n attachmentItem.size = Files.size(p);\n\n UploadSession uploadSession = graphClient.me().messages(message.id).attachments().createUploadSession(attachmentItem).buildRequest().post();\n try(InputStream inputStream = Files.newInputStream(p)) {\n ChunkedUploadProvider\u003cAttachmentItem> chunkedUploadProvider = new ChunkedUploadProvider\u003c>(uploadSession, graphClient, inputStream, attachmentItem.size, AttachmentItem.class);\n \n IProgressCallback\u003cAttachmentItem> progressCallback = new IProgressCallback\u003cAttachmentItem> () {\n @Override\n // Called after each slice of the file is uploaded\n public void progress(final long current, final long max) {\n System.out.println(String.format(\"Uploaded %d bytes of %d total bytes\", current, max));\n }\n\n @Override\n public void success(final AttachmentItem result) {\n System.out.println(String.format(\"Uploaded mail attachment with ID: %s\", result.name));\n }\n\n @Override\n public void failure(ClientException ex) {\n System.out.println(\"Error uploading mail attachment: \" + ex.getMessage());\n throw ex;\n }\n };\n\n chunkedUploadProvider.upload(progressCallback, new int[] {320 * 1024, 1});\n \n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n}\n[AB#5829](https://microsoftgraph.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_workitems/edit/5829)","author":{"url":"https://github.com/jball-vcra","@type":"Person","name":"jball-vcra"},"datePublished":"2020-08-18T00:47:49Z","url":"https://github.com/microsoftgraph/msgraph-sdk-java-auth/issues/52"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:09aaa118-1c15-fe87-5c9e-6554e687758d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BFB0:104CA3:1E40A7:28EC16:6B0511EF |
| html-safe-nonce | 93fccb96b19573dda8a3697dadea83175a0fc63f3a15f35207f3e7e9c74038aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkIwOjEwNENBMzoxRTQwQTc6MjhFQzE2OjZCMDUxMUVGIiwidmlzaXRvcl9pZCI6Ijc3NTI0MjAxOTczMjMzMTM2NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2b6264b51020a4d35a1b226d376461d54e68e384076a4521e079db517f2d076b |
| hovercard-subject-tag | issue:703804369 |
| 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/microsoftgraph/msgraph-sdk-java-auth/52/issue_layout |
| twitter:image | https://opengraph.githubassets.com/138e62ac7b68696c2902a92bb206b521d70f6a8a68a9fe5dd2a3eb7d793b274c/microsoftgraph/msgraph-sdk-java-auth/issues/52 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/138e62ac7b68696c2902a92bb206b521d70f6a8a68a9fe5dd2a3eb7d793b274c/microsoftgraph/msgraph-sdk-java-auth/issues/52 |
| og:image:alt | Expected behavior ChunkedUploadProvider.upload(...) uploads the specified file and attaches it to the message, per https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=java. Actual... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jball-vcra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoftgraph/msgraph-sdk-java-auth git https://github.com/microsoftgraph/msgraph-sdk-java-auth.git |
| octolytics-dimension-user_id | 17304259 |
| octolytics-dimension-user_login | microsoftgraph |
| octolytics-dimension-repository_id | 166441552 |
| octolytics-dimension-repository_nwo | microsoftgraph/msgraph-sdk-java-auth |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 166441552 |
| octolytics-dimension-repository_network_root_nwo | microsoftgraph/msgraph-sdk-java-auth |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width