Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Keycloak Integration
Keycloak Integration [message #1859181] Thu, 18 May 2023 06:09 Go to next message
z232 I is currently offline z232 IFriend
Messages: 48
Registered: February 2016
Member
Hello,

I have developed a web application using Xtext. This application makes HTTP calls to an API using axios, both from the front end and the back end. To enhance security, I have decided to implement a Keycloak adapter for the front end.

Now, I need to figure out how to pass the idToken from the front end to the back end. Can you please provide guidance on this?
Re: Keycloak Integration [message #1859182 is a reply to message #1859181] Thu, 18 May 2023 07:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what do you mean by backend. the xtext servlet?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Keycloak Integration [message #1859183 is a reply to message #1859182] Thu, 18 May 2023 08:00 Go to previous messageGo to next message
z232 I is currently offline z232 IFriend
Messages: 48
Registered: February 2016
Member
yes
Re: Keycloak Integration [message #1859184 is a reply to message #1859183] Thu, 18 May 2023 08:03 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
maybe you can try to override the sendRequest method using javascript means or you directly patch the xtext js files


(i am not a javascript wizard)
require(["webjars/ace/1.3.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				
				var cs = xtext.createServices;
				if (cs) {
					xtext.createServices = function(editor, options) {
						const s = cs.call(this, editor, options);
						for (const property in s) {
							const oldSendRequest = s[property].sendRequest;
							if (oldSendRequest) {
								 editor.xtextServices[property].sendRequest = function(editorContext, settings, needsSession) {
								 	self = this;
								 	settings.data.dullydully="Hello";
								 	oldSendRequest.call(self, editorContext, settings, needsSession);
								 }
							}
						}
						return s;
					}
				}
			
				var editor = xtext.createEditor({
					baseUrl: baseUrl,
					syntaxDefinition: "xtext-resources/generated/mode-mydsl"
				});
				
			});
		});


or does the token need to be send in header?

then maybe something like

//assuming this does not strip anything, otherwise maybe call original beforeSend
settings.beforeSend = function(xhr){xhr.setRequestHeader('X-Test-Header', 'test-value');};


maybe you can also do it globally with

$.ajaxSetup({
				    beforeSend: function(xhr) {
				        xhr.setRequestHeader('X-Test-Header', '...');
				    }
				});


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 18 May 2023 08:46]

Report message to a moderator

Previous Topic:Xtext and (binary) backwards compatibility
Next Topic:Xtext 2.31.0.M3 is out
Goto Forum:
  


Current Time: Thu Apr 25 12:00:19 GMT 2024

Powered by FUDForum. Page generated in 0.03080 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top