cancel
Showing results for 
Search instead for 
Did you mean: 

REST API Authorization

kwiesinger
Champ in-the-making
Champ in-the-making

Hi,

I'm using the ADF-Framework and an Angular app with Typescript for my application.

I want to get nodes via the REST API and the request works flawlessly with Postman. However with Postman I have this extra authorization field I don't have in Typescript.

If I add a Header in my code for the request called Authorization with the value "usernameSmiley Tongueassword" I get a 502 response (The same thing happens if I add the header manually in Postman and don't use the fancy Authorization).

Is there any other way to authorize myself in the headers? I haven't configured an AuthGuard yet, I'm just working on Admin so I would like to set the value of username and password manually.

Regards

5 REPLIES 5

eugenio_romano
Elite Collaborator
Elite Collaborator

If you have to call Alfresco services is better to use the apiService:

https://github.com/Alfresco/alfresco-ng2-components/blob/development/docs/core/services/alfresco-api...

But why can't I simply use the REST-API given by Alfresco?

I found out about my error beforehand and I simply forgot to encode my username and password. Now that I encoded everything and want to do it via Basic Authentication I still get a 401.

All the services in ADF are based on Alfresco REST v1 APIs. old webscripts should be called using ApiService as mentioned by @eugenio_romano 

Regards,
Abbas

Hi kwiesinger,

I think that an example can make this clearer for you:

This is a service method from my code:

constructor(
private alfrescoApiService: AlfrescoApiService,
private errorHandlerService: ErrorHandlerService
) {
this.alfrescoApi = alfrescoApiService.getInstance();
}

getSites
(preset: string😞 Promise<SitePaging> {
let options: object = {orderBy: 'title'};

if (preset) {
options = {where: `(preset=\'${preset}\')`, orderBy: 'title'};
}

return new WebscriptApi(this.alfrescoApi).executeWebScript(
'GET',
'sites',
options,
null,
'api/-default-/public/alfresco/versions/1',
null
).catch(
this.errorHandlerService.handlePromiseError<SitePaging>()
);
}

 It basically executes the following REST call:

https://www.my-alfrescoserver.com/alfresco/api/-default-/public/alfresco/versions/1/sites?preset=%preset%&orderBy=title

Authentication and call handling is done by ADF.