Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare API model / client class for sending through web portal #1615

Closed
Tracked by #1545
tomholub opened this issue Dec 16, 2021 · 9 comments · Fixed by #1619
Closed
Tracked by #1545

prepare API model / client class for sending through web portal #1615

tomholub opened this issue Dec 16, 2021 · 9 comments · Fixed by #1619
Assignees

Comments

@tomholub
Copy link
Collaborator

tomholub commented Dec 16, 2021

part of #1545

Both endpoints accept Authorization header Bearer: IDTOKEN

grabbing a reply token before uploading a message

POST https://fes.<domain>/api/v1/message/new-reply-token

response (json):

data class MessageReplyTokenResponse(
  val replyToken: String
)

uploading message to web portal

POST https://fes.<domain>/api/v1/message

The content of the POST are a http multipart request with fields:

| multipart name | type | structure |
| details | application/json | see below |
| content | application/octet-stream | bytes |

request details structure (json)

data class MessageUploadRequest(
  val associateReplyToken: String, // the value you received when calling the first endpoint
  val from: String, // sender email
  val to: List<String>, // who message will be sent to
  val cc: List<String> = emptyList(), // same, cc
  val bcc: List<String> = emptyList() // same, bcc
)

response structure (json)

data class MessageUploadResponse(
  val url: String
)

With the above info you should be able to successfully make a request to upload a message to web portal. You will get back URL, which if you follow, should exist.

@DenBond7
Copy link
Collaborator

To test code I need to know how to generate | content | application/octet-stream | bytes |. @tomholub Could you share the details? Or can I send any data like content = byteArray(12,13,13,12) and the server will accept it?

@tomholub
Copy link
Collaborator Author

These bytes should contain an OpenPGP-encrypted, armored message.

@DenBond7
Copy link
Collaborator

The content of the POST are a http multipart request with fields:

| multipart name | type | structure |
| details | application/json | see below |
| content | application/octet-stream | bytes |

@tomholub Could you provide a full log? Something is wrong on my side

2021-12-17 18:12:39.613 17972-18074 I/okhttp.OkHttpClient: <-- 200 OK https://fes.flowcrypt.com/api/v1/message/new-reply-token (120ms)
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Date: Mon, 20 Dec 2021 12:54:14 GMT
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Content-Type: application/json
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Content-Length: 59
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Connection: keep-alive
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Access-Control-Allow-Origin: *
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Access-Control-Allow-Credentials: true
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Content-Security-Policy: frame-ancestors 'none'; default-src 'self' 'unsafe-inline' https://flowcrypt-org-web-portal-internal.s3.eu-central-1.amazonaws.com; connect-src 'self' *;
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: Referrer-Policy: no-referrer
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: {
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient:   "replyToken" : "some token"
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: }
2021-12-17 18:12:39.614 17972-18074 I/okhttp.OkHttpClient: <-- END HTTP (59-byte body)
2021-12-17 18:12:39.662 17972-18086 I/okhttp.OkHttpClient: --> POST https://fes.flowcrypt.com/api/v1/message
2021-12-17 18:12:39.662 17972-18086 I/okhttp.OkHttpClient: Content-Type: multipart/form-data; boundary=bf0532e3-204a-4175-8712-5d2ce8cc7b6e
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Length: 1184
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Authorization: Bearer xxxxxx
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: api-version: 3
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: --bf0532e3-204a-4175-8712-5d2ce8cc7b6e
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Disposition: form-data; name="details"
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Transfer-Encoding: binary
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Type: application/json; charset=utf-8
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Length: 146
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: {"associateReplyToken":"some token","bcc":[],"cc":[],"from":"[email protected]","to":["[email protected]"]}
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: --bf0532e3-204a-4175-8712-5d2ce8cc7b6e
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Disposition: form-data; name="content"
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Transfer-Encoding: binary
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Type: application/octet-stream
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Content-Length: 613
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: -----BEGIN PGP MESSAGE-----
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Version: PGPainless
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: hF4D16Pe22XLHvsSAQdApkpmTVPmaoMrX9vNheHxKZmJfuVFOu5ngweMVXKKRhMw
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: iCf735+94l4HNZhOmTfG6MjIb3+bEUWb+sGHh6AuSCX2jHpI32mvRspB5/Ll95vW
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: hF4DTxRYvSK3u1MSAQdAF+mz8vx2OEwpyanJjo5IGiAe84QlNNRgDFHgguoEjC0w
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: HKQ+D8pi4HN73t61BpkYDrgRrBhnWlKIi8Mt8qACfIF1bE5w+yzIA+bEmdf5fEjO
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: 0sAFAY3a0BajVNWslVsVPOCgiE0QGp1NtSM+wgOIRbtyLLlXVRUiF27fEXkfXaBs
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: YlB1+OQATbsioLYtEJSPrPqCjcVlaTcVw3P/DnfhSatqKSiZHgWs86nDc5F2wJ9/
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Gx8nnNirV0hGS6WCQ1S2Jlwk46f7jXmWUljrTYKoF37Izfj+CPO1eaN+NxUwEepn
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: rLK0B2xme3ihZ/lSl4WTOfY1VK9e4OfD18sBkN+rm2RHZM3bqJSp3UvjgD7anS5N
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: Eel5cegx/h8=
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: =Cs9G
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: -----END PGP MESSAGE-----
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: --bf0532e3-204a-4175-8712-5d2ce8cc7b6e--
2021-12-17 18:12:39.663 17972-18086 I/okhttp.OkHttpClient: --> END POST (1184-byte body)
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: <-- 400 Bad Request https://fes.flowcrypt.com/api/v1/message (186ms)
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Date: Mon, 20 Dec 2021 12:54:14 GMT
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Content-Type: application/json
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Content-Length: 86
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Connection: keep-alive
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Access-Control-Allow-Origin: *
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Access-Control-Allow-Credentials: true
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Content-Security-Policy: frame-ancestors 'none'; default-src 'self' 'unsafe-inline' https://flowcrypt-org-web-portal-internal.s3.eu-central-1.amazonaws.com; connect-src 'self' *;
2021-12-17 18:12:39.850 17972-18086 I/okhttp.OkHttpClient: Referrer-Policy: no-referrer
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient: {
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient:   "code" : 400,
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient:   "message" : "Bad request",
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient:   "details" : "Missing uploaded file"
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient: }
2021-12-17 18:12:39.851 17972-18086 I/okhttp.OkHttpClient: <-- END HTTP (86-byte body)

@DenBond7
Copy link
Collaborator

I've found a reason

was

Content-Disposition: form-data; name="content"

should be

Content-Disposition: form-data; name="content"; filename="content"

@DenBond7
Copy link
Collaborator

But I still can't complete the request

{
2021-12-20 16:41:13.199 6502-6841 I/okhttp.OkHttpClient:   "code" : 400,
2021-12-20 16:41:13.199 6502-6841 I/okhttp.OkHttpClient:   "message" : "Uploaded file doesn't contain a valid PGP message",
2021-12-20 16:41:13.199 6502-6841 I/okhttp.OkHttpClient:   "details" : "For more details, see FlowCrypt Enterprise Server logs."
2021-12-20 16:41:13.199 6502-6841 I/okhttp.OkHttpClient: }

I used a correct PGP message(I use it in tests)

-----BEGIN PGP MESSAGE-----
Version: PGPainless

hF4D16Pe22XLHvsSAQdApkpmTVPmaoMrX9vNheHxKZmJfuVFOu5ngweMVXKKRhMw
iCf735+94l4HNZhOmTfG6MjIb3+bEUWb+sGHh6AuSCX2jHpI32mvRspB5/Ll95vW
hF4DTxRYvSK3u1MSAQdAF+mz8vx2OEwpyanJjo5IGiAe84QlNNRgDFHgguoEjC0w
HKQ+D8pi4HN73t61BpkYDrgRrBhnWlKIi8Mt8qACfIF1bE5w+yzIA+bEmdf5fEjO
0sAFAY3a0BajVNWslVsVPOCgiE0QGp1NtSM+wgOIRbtyLLlXVRUiF27fEXkfXaBs
YlB1+OQATbsioLYtEJSPrPqCjcVlaTcVw3P/DnfhSatqKSiZHgWs86nDc5F2wJ9/
Gx8nnNirV0hGS6WCQ1S2Jlwk46f7jXmWUljrTYKoF37Izfj+CPO1eaN+NxUwEepn
rLK0B2xme3ihZ/lSl4WTOfY1VK9e4OfD18sBkN+rm2RHZM3bqJSp3UvjgD7anS5N
Eel5cegx/h8=
=Cs9G
-----END PGP MESSAGE-----

@IvanPizhenko
Copy link
Contributor

I will try to check why FES rejects this message.

@IvanPizhenko
Copy link
Contributor

@IvanPizhenko
Copy link
Contributor

@DenBond7 I will fix this in FES, but meanwhile as as workaround please ensure that you have \n in the end of PGP message block, i.e. after last - in the -----END PGP MESSAGE-----.

@DenBond7
Copy link
Collaborator

@DenBond7 I will fix this in FES, but meanwhile as as workaround please ensure that you have \n in the end of PGP message block, i.e. after last - in the -----END PGP MESSAGE-----.

Thank you for the fast feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants