[Angular2][javascript] View user logged in

Hello,

I am creating an angular application who provide some features of the Camunda TaskList. I use the basic camunda authentification and I would like to show the user (user id) logged in after connection.

I’ve tried to find the information on the $rootScope but isn’t an angular way and anyway I did’nt find it.

I see there is no build-in process variable for that. So did somebody know how(where) to get this information ?

If you want some further informations, please don’t hesitate. thanks for reading this post.

ps : sorry for bad english

1 Like

Hi,

you can find an example about how to get the user name in an embedded form in the documentation.

Does that help you?

Cheers
Sebastian

thanks for the answer but I’ve already tried that. Maybe I make it bad.

I’ve tried to add this script from my home page but the script doesn’t load.
I’ve also tried to add it on the start-form of a process but $rootScope do not contain authentification field.

If needing, I can try it again and share some files with the error logs.

there is some files of my first project using angularJS :
http://plnkr.co/edit/Rx7Q5WLAS0h8zhN1e43n?p=catalogue
(it’s not running, just to show the files)

In this case (add the script on home.html) I got no error but the script is not execute

In case where I set the script on start-form of my process (not really what I want but for the test), I got :

Uncaught TypeError: Cannot read property ‘name’ of undefined
at new eval (eval at (camunda-bpm-sdk-angular.js:73), :4:54)
at d (angular-1.2.29.min.js:35)
at Object.instantiate (angular-1.2.29.min.js:35)
at inject (camunda-bpm-sdk-angular.js:66)
at eval (eval at (camunda-bpm-sdk-angular.js:73), :3:9)
at camunda-bpm-sdk-angular.js:73
at child.executeFormScript (camunda-bpm-sdk-angular.js:76)
at child.CamundaForm.executeFormScripts (camunda-bpm-sdk-angular.js:4243)
at child.CamundaForm.initializeForm (camunda-bpm-sdk-angular.js:4189)
at done (camunda-bpm-sdk-angular.js:4131)

Are you able to use embedded forms without this custom Javascript or do embedded forms not work for you at all?

I’ve create my own process with .bpmn, I can launch the start-form of this process on my application (like the browser-forms-angular example)
it’s launch the embedded forms.

but directly on my own web-application the script is just ignore.

edit : I think the script type “text/form-script” isn’t recognized

Yep, that’s expected. text/form-script can only be used for the embedded forms. If you want to extend and customize the Tasklist itself, you can have a look at Tasklist plugins or custom scripts.

So it’s impossible to get the current user from browser-form-angular (for example) by using the rest-api or by getting info from the authentication filter?

Basically, your application needs to take care of user authentication. If you are using Tasklist, it is stored on the $rootScope. Since you are building your own application, you need to handle that yourself.

Could you detail how you log the user in? Which requests are send and to which endpoint?

1 Like

I’m using the basic authentification of camunda (configure auth) and do nothing else.

during my connection there is nothing related to the connection, only some request to the rest-api (my request).

there is my $rootScope :

h {$id: “001”, $$childTail: a.$…s.$$childScopeClass, $$childHead: a.$…s.$$childScopeClass, $$prevSibling: null, $$nextSibling: null…}
$$asyncQueue:Array(0)
$$childHead:h
$$childScopeClass:function ()
$$childTail:h
$$destroyed:false
$$isolateBindings:Object
$$listenerCount:Object
$$listeners:Object
$$nextSibling:null
$$phase:null
$$postDigestQueue:Array(0)
$$prevSibling:null
$$watchers:Array(2)
$id:“001”
$parent:null
$root:h
this:h
proto:Object

so thanks for your time and your answers, I will tried to find/replace the authentification.

Hi @ethaqnix,

I can see that camunda is using following request to render cockpit page:

curl 'http://localhost:8080/camunda/api/admin/auth/user/default' -H 'Cookie: JSESSIONID=71FEF37A39E250AD5364D99A2108E8D2' -H 'Accept: application/json, text/plain, */*' -H 'Referer: http://localhost:8080/camunda/app/cockpit/default/' -H 'X-Authorized-Engine: default' -H 'Connection: keep-alive' --compressed

which returns

{"userId":"demo","authorizedApps":["admin","tasklist","welcome","cockpit"]}
Is that what you are looking for?

Cheers,
Askar

thanks, this is exactly what I’m looking for.
however I have some problems, I don’t have any cookie called JSESSIONID and I don’t understand 'Referer: http://localhost:8080/camunda/app/cockpit/default/'.

I don’t wan’t to take more of your time so I will look at the sources of the camunda webapp and come back if I have some more precise questions.

Hey @ethaqnix,

referrer you can skip. And JSESSIONID will be added to cookies after you pass authentication.

Cheers,
Askar

Hello !

Its finally works.
I didn’t have the JSESSIONID because the basic auth provide by camunda wasn’t directly on my own app. So now I connect by this request :

let url = “http://localhost:8080/camunda/api/admin/auth/user/default/login/welcome”;
let headers = new Headers();
headers.append(‘Content-Type’, ‘application/x-www-form-urlencoded’);
headers.append(‘Accept’, ‘application/json, text/plain, /’);
headers.append(‘X-Authorized-Engine’, ‘default’);
let options = new RequestOptions({ headers: headers });
let formData = “username=” + username + " &password=" + password;
this.http.post(url, formData, options).map(function (resp) {
return (resp);
}).subscribe(function (response) {
console.log(response);
});
it’s create the JSESSIONID then I can use your request aakhmerov to find the current user.

Thank you again to all !

1 Like