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

Receiving the message: "401 - Not authenticated" to the logged-in agent #152

Open
jrleles opened this issue Mar 3, 2020 · 1 comment
Open

Comments

@jrleles
Copy link

jrleles commented Mar 3, 2020

Hello, I developed an API that accesses resources on my pod. Access to resources requires the user to authenticate. The user authenticates to a web application that consumes the API. The application uses the solid auth client. After authentication, the API is called and the resources are read from the pod and returned to the user. However, it only works if access is granted to the general public (acl:agentClass foaf:Agent). When I grant access to an individual agent (acl:agent https://jleles.solid.community/profile/card#me), I receive the following message: "401 - Unauthenticated".
How to solve this? Thanks to anyone who can help!

.acl

<#authorization>
    a acl:Authorization;
   acl:agent <https://jleles.solid.community/profile/card#me>;
    acl:accessTo <./file1.owl>;
    acl:default <./>;
    acl:mode acl:Read.

index.html

<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8"/>
<title>Example Application</title>
</head>
<body>
     <p id="login">
        You are not logged in.
        <button>Log in</button>
     </p>
     <p id="logout">
        You are logged in as <span id="user"></span>.
        <button>Log out</button>
     </p>
    <script src="jquery.js"></script>
    <script src="solid-auth-client.bundle.js"></script>
    <script src="main.js"></script>
</body>
</html>

main.js

// Log the user in and out on click
const popupUri = 'popup.html';
$('#login  button').click(() => solid.auth.popupLogin({ popupUri }));
$('#logout button').click(() => solid.auth.logout());

// Update components to match the user's login status
solid.auth.trackSession(session => {
  const loggedIn = !!session;
  $('#login').toggle(!loggedIn);
  $('#logout').toggle(loggedIn);
  if (loggedIn) {
    $('#user').text(session.webId);
    solid.auth.fetch(URL_API).then(response => { response.json().then(data => { console.log(data) })});
   }
});

console.log view

{timestamp: "2020-03-03T15:49:17.864+0000", status: 500, error: "Internal Server Error", message: "401 - Unauthenticated", path: "..."}

@jaxoncreed
Copy link
Contributor

Could you check your network logs show me the requests that are being made. Send me the curls by following this https://www.alexkras.com/copy-any-api-call-as-curl-request-with-chrome-developer-tools/

Be sure to not include your "authorization" header

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

No branches or pull requests

2 participants