cancel
Showing results for 
Search instead for 
Did you mean: 

ADF: 401 (Unauthorized)

mag
Champ on-the-rise
Champ on-the-rise

Hello all,

I am using ADF 7.x to create a custom component. However, I am encountering an issue when trying to use a REST API. Please find below the error message and my custom service:

mag_0-1745350576830.png

private baseUrl = '/alfresco/api/-default-/public/workflow/versions/1';
getUserTasks(){
 return this.http.get(`${this.baseUrl}/tasks`);
  }
NB: note that we could connect into the application and all out of the box features are working.
 
Thanks,

 

1 REPLY 1

roberto_gamiz
Star Contributor
Star Contributor

Hi,

You are using standar angular http client module to implement the communication with alfresco repository  so you need to add an Authentication Header to the call to obtain  access to the resources.

Yo could try to use the AlfrescoApiService from ADF components to establish the comunication so the adf modules handle the authentication layer for you. 

 

Example:

import { AlfrescoApiService } from '@alfresco/adf-content-services';
....
....

constructor(
....
private apiService: AlfrescoApiService,
....
){
....
....

public executeWebScript(
httpMethod: string,
scriptPath: string,
scriptArgs?: any,
contextRoot?: string,
servicePath?: string,
postBody?: any
😞 Promise<any> {
contextRoot = contextRoot || 'alfresco';
servicePath = servicePath || 'service';
postBody = postBody || null;

const allowedMethod: string[] = ['GET', 'POST', 'PUT', 'DELETE'];

if (!httpMethod || allowedMethod.indexOf(httpMethod) === -1) {
throw 'method allowed value GET, POST, PUT and DELETE';
}

if (!scriptPath) {
throw 'Missing param scriptPath in executeWebScript';
}

const contentTypes = ['application/json'];
const accepts = ['application/json', 'text/html'];
return this.apiService
.getInstance()
.contentClient.callApi(scriptPath, httpMethod, {}, scriptArgs, {}, {}, postBody, contentTypes, accepts, null, contextRoot + '/' + servicePath);
}



 

Regards