question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to follow links from POST-only resources

See original GitHub issue

I’ve got a situation where I’ve got a resource that doesn’t really exist, but that I still want to follow links from.

I’m building a login/register flow, where the client will:

  • Perform a POST to /authentication with the username.
  • Receive a response containing one of two links - identified as either rels/authentication/authenticate or rels/authentication/register - depending on whether the username exists.
  • Perform a POST to the link that was returned with the appropriate details.

So what I’ve done is:

  • Create a new Ketting Client.)
  • Perform a GET to / to get the home document
  • Follow the link with the rel rels/authentication and perform a POST to this with the username - this is /authentication
  • Follow the link with the rel rels/authentication/authenticate and perform a `POST to this with the username and password.

The result is that Ketting is then trying to do a GET to /authentication, which returns an error because the server can’t handle that, and then it errors out.

The code is effectively like this: (Restructured a little bit for brevity)

        const startAuthResource = await apiRoot.follow("rels/authentication");
        const response = await startAuthResource.post({ data: { username } });
        const authResource = await startAuthResource.follow("rels/authentication/authenticate"); // <-- Problem occurs here

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
evertcommented, Jan 3, 2021

Yeahh… this is an issue.

The problem is that, generally, when following links, we follow links from a resource to another resource. When we get a POST response, the body of the response is not necessarily the representation of that startAuthResource resource.

There’s two paths to make better, and I also have a workaround:

Approach 1: The response to the POST response should be considered to be the representation of that resource. The obvious header for this is Content-Location:

https://tools.ietf.org/html/rfc7231#section-3.1.4.2

If this makes the most sense for your case, we could add this feature to Ketting.

Approach 2: Follow links from State objects.

I had the idea to add a .follow() function to State objects. This would allow you to follow links from any body, not just things that are ‘resources’:

 const startAuthResource = await apiRoot.follow("rels/authentication");
 const response = await startAuthResource.post({ data: { username } });
 const authResource = response.follow("rels/authentication/authenticate"); // <-- We're following from 'response'

Workaround:

const startAuthResource = await apiRoot.follow("rels/authentication");
const response = await startAuthResource.post({ data: { username } });
const authResource = startAuthResource.go(response.links.get("rels/authentication/authenticate").href);

Sidenote is that it would also be nice if you could pass a Link type to .go() so that last snippet would look like:

const startAuthResource = await apiRoot.follow("rels/authentication");
const response = await startAuthResource.post({ data: { username } });
const authResource = startAuthResource.go(response.links.get("rels/authentication/authenticate"));
0reactions
evertcommented, Jan 3, 2021

Open a few more tickets for this. I think we’ll probably have a version 7 this month. Thanks for the report!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serving static web resources in Spring Boot & Spring Security ...
Problem. After I enabled Spring Security, hitting the static resource URL requires authentication. My relevent Spring Security Java config looks ...
Read more >
I Can't Get My Hyperlink to Work - Small Business - Chron.com
If the hyperlink doesn't work correctly, troubleshoot the problem by checking the link ... default Web browser and open the linked page or...
Read more >
How to share links on LinkedIn - John Espirian
Truthful answer: we can't be sure. But here's my best theory … LinkedIn pays attention to the state of the post only when...
Read more >
How To: Get embed token using Get/Post only - Microsoft ...
Go to the Microsoft Power BI Embedded Sample site (link) and test your report. The input fields are as follows: Embed Token: {token...
Read more >
Fix broken links to data - Microsoft Support
If you can't find or don't have access to the document that you originally linked to, you can prevent Excel from trying to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found