REST API Authorization

cancel
Showing results for 
Search instead for 
Did you mean: 
kwiesinger
Member II

REST API Authorization

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
eugenio_romano
Alfresco Employee

Re: REST API Authorization

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...

kwiesinger
Member II

Re: REST API Authorization

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.

abbask01
Senior Member

Re: REST API Authorization

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
d_moeyersons
Customer

Re: REST API Authorization

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.

kwiesinger
Member II

Re: REST API Authorization

Thank you for your reply, this was really helpfull and I will try it ASAP.

So it is not only Read-Only? (I read it somewhere in the Alfresco wiki).
Also due to the fact that I'm new to angular (learned it a few months ago): I can't simply use the HttpClient for this? I have to write/ use this Webscript API?

Is there a complete documentation in general about this Javascript API, I find github a bit confusing.

 

Regards