# Launching script after user AD authentication

**URL:** <https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 4, 2023, 2:08pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209 "2023-01-04T14:08:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![valentin.guichard](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@valentin.guichard](https://forum.inductiveautomation.com/u/valentin.guichard)\
**Post date:** [January 4, 2023, 2:08pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/1 "2023-01-04T14:08:30Z")

</div>

Hi,  
Is there a way to run a script after a user get logged in the application.  
I tried to do something with the Authentication challenge session event (just writing a log with the system.util.getLogger()) but it's not working.  
Any idea ?  
Best regards,  
Valentin

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 4, 2023, 3:12pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/2 "2023-01-04T15:12:59Z")

</div>

What are you trying to do ?

---

<div class="post-metadata">

**Author:** ![valentin.guichard](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@valentin.guichard](https://forum.inductiveautomation.com/u/valentin.guichard)\
**Post date:** [January 4, 2023, 3:14pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/3 "2023-01-04T15:14:24Z")

</div>

I'm trying to affect values to session custom properties when a user get logged in the perspective session

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 4, 2023, 3:18pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/4 "2023-01-04T15:18:31Z")

</div>

The session startup event should work.

Otherwise, if you can be a bit more accurate about your goal, someone around here might suggest alternative (and maybe better) ways of achieving it.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [January 4, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/5 "2023-01-04T15:19:33Z")

</div>

weird i dont seem to be able to log anything either in this event

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 4, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/6 "2023-01-04T15:21:58Z")

</div>

Did you mean the startup one, or the auth challenge one ?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [January 4, 2023, 3:22pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/7 "2023-01-04T15:22:56Z")

</div>

the challange

---

<div class="post-metadata">

**Author:** ![valentin.guichard](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@valentin.guichard](https://forum.inductiveautomation.com/u/valentin.guichard)\
**Post date:** [January 4, 2023, 3:23pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/8 "2023-01-04T15:23:47Z")

</div>

I want to use this event to manage my security.  
I created session custom properties as boolean and the goal is to check the role which get logged and affect the value "True" for this customs.  
I already know the function HasRole()... But I don't want to use it like that to prevent about some change on group name or something else. I want my security to be centralized in one script.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 4, 2023, 3:28pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/9 "2023-01-04T15:28:23Z")

</div>

I'm kind of thinking 'authentication challenge' means something else:  
[https://docs.inductiveautomation.com/display/DOC81/Component+Events+and+Actions#ComponentEventsandActions-AuthenticationChallengeAction](https://docs.inductiveautomation.com/display/DOC81/Component+Events+and+Actions#ComponentEventsandActions-AuthenticationChallengeAction)

> [@valentin.guichard](#):
>
> I created session custom properties as boolean and the goal is to check the role which get logged and affect the value "True" for this customs.

You could use `session.props.auth.user.roles` instead.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [January 4, 2023, 3:30pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/10 "2023-01-04T15:30:48Z")

</div>

seems like it yea

---

<div class="post-metadata">

**Author:** ![Sheko29](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sheko29/32/25082_2.png) [@Sheko29](https://forum.inductiveautomation.com/u/Sheko29)\
**Post date:** [January 4, 2023, 3:44pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/11 "2023-01-04T15:44:17Z")

</div>

> [@valentin.guichard](#):
>
> system.util.getLogger()

I just try an authentication challenge with [system.perspective.authenticationChallenge](https://docs.inductiveautomation.com/display/DOC81/system.perspective.authenticationChallenge) and it triggers successfully the Session event Authentication Challenge, but the project name is not the correct 😅

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8e06cccdb01e7fca06fe3f2f8cf2edee8072b7e6.png)

but I'm not sure this event works with normal loggin...

---

<div class="post-metadata">

**Author:** ![valentin.guichard](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@valentin.guichard](https://forum.inductiveautomation.com/u/valentin.guichard)\
**Post date:** [January 4, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/12 "2023-01-04T15:52:09Z")

</div>

Yeah I will try to add a change script on the user id and see what's going to happend 🙂

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 4, 2023, 4:20pm UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/13 "2023-01-04T16:20:05Z")

</div>

Why a change script ?  
Just bind on the current user's roles.  
If you want to check for a particular role, add a script transform:

```python
return "your_particular_role" in value

```

---

<div class="post-metadata">

**Author:** ![valentin.guichard](https://avatars.discourse-cdn.com/v4/letter/v/2bfe46/32.png) [@valentin.guichard](https://forum.inductiveautomation.com/u/valentin.guichard)\
**Post date:** [January 5, 2023, 8:11am UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/14 "2023-01-05T08:11:54Z")

</div>

I need a change script to set values to a lot of sessisons custom properties.  
What I did:

- I Created a session custom property 'Authenticated' and I bind it on the session prop props.auth.authenticated cause you can't add change script on the session props directly (you can do it but it's not working)
- Add a change script on my new custom and did:

```auto
if 'myrole' in self.props.auth.user.roles :
		self.custom.Matrice.right1= True
		self.custom.Matrice.right2= True
		self.custom.Matrice.right3= True
		self.custom.Matrice.right4= True
		self.custom.Matrice.right5= True
.........

```

This working well, thank all for your answer 🙂

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 5, 2023, 8:39am UTC](https://forum.inductiveautomation.com/t/launching-script-after-user-ad-authentication/68209/15 "2023-01-05T08:39:52Z")

</div>

That's a perfectly valid use case for bindings.
