Skip to content

Commit

Permalink
fix: align consent script wrt latest AS updates (#10780)
Browse files Browse the repository at this point in the history
* fix: align script wrt latest AS consent updates #10766

Signed-off-by: jgomer2001 <[email protected]>

* docs: update Agama consent docs #10766

Signed-off-by: jgomer2001 <[email protected]>

* docs: change keyword #10766

Signed-off-by: jgomer2001 <[email protected]>

---------

Signed-off-by: jgomer2001 <[email protected]>
Co-authored-by: YuriyZ <[email protected]>
  • Loading branch information
jgomer2001 and yuriyz authored Feb 3, 2025
1 parent 80f0b63 commit 6cb802b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
23 changes: 6 additions & 17 deletions docs/script-catalog/consent_gathering/AgamaConsentGathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,20 @@ def prepareForStep(self, step, context):
print "Agama-Consent. Failed to retrieve session_id"
return False

cesar = session.getSessionAttributes()
param = cesar.get("agama_flow")
sessionId = session.getId()
# print "Session id is %s" % sessionId
param = context.getSessionAttributes().get("consent_flow")

if not param:
param = self.extractAgamaFlow(cesar.get("acr_values"))
print "Agama-Consent. 'consent_flow' session attribute missing"
return False

if not param:
print "Agama-Consent. Unable to determine the Agama flow to launch. Check the docs"
return False

(qn, ins) = self.extractParams(param)
if qn == None:
print "Agama-Consent. Unable to determine the Agama flow to launch. Check the docs"
return False

try:
sessionId = session.getId()
# print "==================================== %s" % sessionId

bridge = CdiUtil.bean(NativeJansFlowBridge)
running = bridge.prepareFlow(sessionId, qn, ins, False, self.enterUrl)

Expand All @@ -120,13 +115,7 @@ def getPageForStep(self, step, context):
return "/" + self.enterUrl

# Misc routines

def extractAgamaFlow(self, acr):
prefix = "agama_"
if acr and acr.startswith(prefix):
return acr[len(prefix):]
return None


def extractParams(self, param):

# param must be of the form QN-INPUT where QN is the qualified name of the flow to launch
Expand Down
31 changes: 30 additions & 1 deletion docs/script-catalog/consent_gathering/consent-gathering.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tags:
- administration
- developer
- script-catalog
- ConsentGathering
- consent
---

## Overview
Expand Down Expand Up @@ -262,3 +262,32 @@ This is how consent will work depending on the authentication request issued:
- With `agama_co.acme.mysuperflow`, the Agama flow `io.jans.consent.B` will be launched for consent

Agama flows used for consent can be built using the same approach and tooling used for regular authentication flows. Note however there is no need to pass a user identity in the `Finish` instruction. If passed, it will be ignored, thus, it suffices to end a consent flow with `Finish false/true`.

### Getting contextual data

To access information in your Agama consent flow related to the user attempting login, scopes requested, etc., get an instance of managed bean `io.jans.as.server.util.AgamaConsentUtil` and use the available methods as summarized below:

|Method|Description|Reference class|
|-|-|-|
|`getClient`|Gets a reference to the OAuth client associated to the authentication request|[Client](https://github.com/JanssenProject/jans/tree/vreplace-janssen-version/jans-auth-server/common/src/main/java/io/jans/as/common/model/registration/Client.java)|
|`getScopes`|A list of OAuth scopes requested|[Scope](https://github.com/JanssenProject/jans/tree/vreplace-janssen-version/jans-auth-server/persistence-model/src/main/java/io/jans/as/persistence/model/Scope.java)|
|`getUser`|A reference to the user attempting authentication|[User](https://github.com/JanssenProject/jans/tree/vreplace-janssen-version/jans-auth-server/common/src/main/java/io/jans/as/common/model/common/User.java) / [SimpleUser](https://github.com/JanssenProject/jans/tree/vreplace-janssen-version/jans-core/model/src/main/java/io/jans/model/user/SimpleUser.java)|
|`getSessionAttributes`|A map containing the parameters of the OAuth authentication request issued||

Java example code:

```
import io.jans.as.server.util.AgamaConsentUtil;
import io.jans.service.cdi.util.CdiUtil;
...
AgamaConsentUtil acu = CdiUtil.bean(AgamaConsentUtil.class);
String name = acu.getClient().getClientName(); //retrieves the client's display name
```

Agama DSL example:

```
acuCls = Call io.jans.as.server.util.AgamaConsentUtil#class
acu = Call io.jans.service.cdi.util.CdiUtil#bean acuCls
name = acu.client.clientName //retrieves the client's display name
```

0 comments on commit 6cb802b

Please sign in to comment.