How can I get value from client script node

This topic contains 1 reply, has 2 voices, and was last updated by  James Phillpotts 2 months ago.

  • Author
    Posts
  • #24804
     montyp136 
    Participant

    I have created client auth tree node with below code

    
    @Node.Metadata(outcomeProvider = SingleOutcomeNode.OutcomeProvider.class, configClass = ClientScriptGetTokenNode.Config.class)
    public class ClientScriptGetTokenNode extends SingleOutcomeNode {
    
    	private final Config config;
    	private final static String DEBUG_FILE = "ScriptedClientNode";
    	protected Debug debug = Debug.getInstance(DEBUG_FILE);
    
    	public interface Config {
    		@Attribute(order = 100)
    		@Script(AUTHENTICATION_CLIENT_SIDE_NAME)
    		ScriptConfiguration script();
    
    		@Attribute(order = 200)
    		String scriptResult();
    	}
    
    	@Inject
    	public ClientScriptGetTokenNode(@Assisted Config config) throws NodeProcessException {
    		this.config = config;
    	}
    
    	@Override
    	public Action process(TreeContext context) throws NodeProcessException {
    		Optional<String> result = context.getCallback(HiddenValueCallback.class).map(HiddenValueCallback::getValue)
    				.filter(scriptOutput -> !Strings.isNullOrEmpty(scriptOutput));
    		if (result.isPresent()) {
    			JsonValue newSharedState = context.sharedState.copy();
    			newSharedState.put(config.scriptResult(), result.get());
    			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>IF");
    			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>"+config.scriptResult() +">>>>"+result.get());
    			debug.message("[" + this.getClass().getSimpleName() + "]" + "Client result is:\n" + result.get());
    			return goToNext().replaceSharedState(newSharedState).build();
    		} else {
    			String clientSideScript = config.script().getScript();
    			debug.message("[" + this.getClass().getSimpleName() + "] " + "Client script is:\n" + clientSideScript + "\n"
    					+ "Client result name: " + config.scriptResult());
    			ScriptTextOutputCallback scriptCallback = new ScriptTextOutputCallback(clientSideScript);
    			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>ELSE");
    			HiddenValueCallback hiddenValueCallback = new HiddenValueCallback(config.scriptResult());
    			ImmutableList<Callback> callbacks = ImmutableList.of(scriptCallback, hiddenValueCallback);
    			return send(callbacks).build();
    		}
    	}
    }
    

    Client Script

    
    var ssoToken ="XXXXXXXXXXXXXXXXXXXXX";
    

    How Can I get ssoToken value from result.get()

    #24806
     James Phillpotts 
    Moderator

    To obtain a value from the browser, you would need to use the DOM API to set the value of the hidden <input.../> element for the hidden input callback, which will have an id of something like IDToken2, and then trigger submission of the page.

    HTH.
    James

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

©2019 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?