Skip to main content

Hi,

I´m currently working on a custom webpage for data delivery.

 

I´ve used some code from the following example in FME Playground: https://playground.fmeserver.com/javascript/data-delivery/open-layers-integration/

 

I´m wondering how it´s possible to change the token in the FMEServer.init below, to a token that is generated thru the example here: https://playground.fmeserver.com/javascript/authorization/request-a-token/

 

Pre-generated setup for the token:

FMEServer.init({

server : "https://demos-safe-software.fmecloud.com",

token : "568c604bc1f235bbe137c514e7c61a8436043070"

});

 

I want to use the "guestToken" thats been generated in the Javascript below instead:

function processToken(token) {

if( typeof token == 'string' ){

guestToken = token.trim();

} else {

guestToken = "<pre>"+JSON.stringify(token, undefined, 4)+"</pre>";

}

 

Both codes works sepetratly in the same project, but rather then parse the token into a new div in the html-file, i would like to use it as the token.

I´m not that used at Javascrpt to get this to work, but maybe someone else?

 

Or is there any other, more simple way to accomplish this task?

I´ve tried to work thru the documentation but nothing leads me to a conclusion.

Thanks in advance

Hi @eetmyhouse

Just to check, how would you want your app to work with respect to authentication? Do you want a user to have to enter their FME Server username and password before submitting a request to FME Server or would you want it to work without requiring manual authentication?

If you don't need to have a user enter their name and password, I'd recommend creating a token directly in the FME Server interface first, then using that token directly within your app (instead of using the FMEServer.generateToken call). You can use your own token directly by replacing the server URL and token with your own in the FMEServer.init call.


Hi @eetmyhouse

Just to check, how would you want your app to work with respect to authentication? Do you want a user to have to enter their FME Server username and password before submitting a request to FME Server or would you want it to work without requiring manual authentication?

If you don't need to have a user enter their name and password, I'd recommend creating a token directly in the FME Server interface first, then using that token directly within your app (instead of using the FMEServer.generateToken call). You can use your own token directly by replacing the server URL and token with your own in the FMEServer.init call.

I @LauraAtSafe, thanks for your awnser.

 

 

I just realised that what I wanted might not work and also that my question wasn´t explaiend to well.

 

However, I´m after the first way that you described.

My tought was to use the login-service to generate a token and therefore access to run the workspace who clipps the data. So only persons with a login could use the service.

 

In the current setup, I have a token pre generated to the guest account so that anyone who access the website thru the URL are able to run the workspace. But I would rather have a more limited access site where only persons with knowledge of a user and password can use it.

 

 

So I thougt that, if I can get the token generated from from the login-service to be used with the clipping-workspace that should've been a fairly simple task to set up considering that they work separetly i the same site.

But, as i said first, that might not work considering that the login-service also need access with a token to run. So if theFMEServer.init would be like:

"FMEServer.init({

server : "http://shfme01:8080/",

token : "guestToken"

});"

(Or how it would´ve worked).Tthe login-service would presumably fail because it can't run if the token isn´t defined.

Maybe there is a way to let the login-service to use the guest-token that is pre generated and that the clipping workspace can use the generated token from the login-service somehow?

Or is it any other way to accomplish this?

Is it possible to use the url instead? Obviously not as safe, as evething is naked in the URL, but still could be handy.

ex.

 

http://<fmeserver>/<sitename>/user=&password=&token=?

 

 

 

 


I @LauraAtSafe, thanks for your awnser.

 

 

I just realised that what I wanted might not work and also that my question wasn´t explaiend to well.

 

However, I´m after the first way that you described.

My tought was to use the login-service to generate a token and therefore access to run the workspace who clipps the data. So only persons with a login could use the service.

 

In the current setup, I have a token pre generated to the guest account so that anyone who access the website thru the URL are able to run the workspace. But I would rather have a more limited access site where only persons with knowledge of a user and password can use it.

 

 

So I thougt that, if I can get the token generated from from the login-service to be used with the clipping-workspace that should've been a fairly simple task to set up considering that they work separetly i the same site.

But, as i said first, that might not work considering that the login-service also need access with a token to run. So if theFMEServer.init would be like:

"FMEServer.init({

server : "http://shfme01:8080/",

token : "guestToken"

});"

(Or how it would´ve worked).Tthe login-service would presumably fail because it can't run if the token isn´t defined.

Maybe there is a way to let the login-service to use the guest-token that is pre generated and that the clipping workspace can use the generated token from the login-service somehow?

Or is it any other way to accomplish this?

Is it possible to use the url instead? Obviously not as safe, as evething is naked in the URL, but still could be handy.

ex.

 

http://<fmeserver>/<sitename>/user=&password=&token=?

 

 

 

 

Hi @eetmyhouse, I see! Yes, that is a problem with our current implementation of the fme server javascript API where it needs a token to generate a token. That is on our radar for fixing, but I'm not sure what the timeline for that might be.

Yes, you can use the URL instead to generate the token. There's information on how that works near the bottom of this page in our documentation: https://docs.safe.com/fme/html/FME_Server_Documentation/Content/ReferenceManual/service_token.htm


@eetmyhouse

Take a look at this example for generating a token on our playground:

 

https://playground.fmeserver.com/getting-started/authentication/

It will allow you to generate a token by providing a username and password without having to initiate the FME Server JS API. The token that is returned by the triggerRequestGenerateToken() function can then be passed into the FMEServer.init() function.

I hope this helps!


@eetmyhouse

Take a look at this example for generating a token on our playground:

 

https://playground.fmeserver.com/getting-started/authentication/

It will allow you to generate a token by providing a username and password without having to initiate the FME Server JS API. The token that is returned by the triggerRequestGenerateToken() function can then be passed into the FMEServer.init() function.

I hope this helps!

Hi @GerhardAtSafe,

 

 

This seem like a way that can be usfull in the meantime.

 

However, like I said in the question, I´m not that used to configure Javascripts. I´m in a learing process.

 

Do you have any ideas how to get the "xhReq.responseText" to the FMEServer.init token?

Hi @GerhardAtSafe,

 

 

This seem like a way that can be usfull in the meantime.

 

However, like I said in the question, I´m not that used to configure Javascripts. I´m in a learing process.

 

Do you have any ideas how to get the "xhReq.responseText" to the FMEServer.init token?

There are a lot of ways to do that and it really depends on your project. One option is to use the response of the token request in the FMEServer.init() function directly  instead of returning the response of the request in alert() function like this:

FMEServer.init({ server : "your_server", token : xhReq.responseText });

Hi @GerhardAtSafe,

 

 

This seem like a way that can be usfull in the meantime.

 

However, like I said in the question, I´m not that used to configure Javascripts. I´m in a learing process.

 

Do you have any ideas how to get the "xhReq.responseText" to the FMEServer.init token?

Please also have a look this free training:

 

https://www.safe.com/training/recorded/fme-server-2018-rest-api/

Hi @eetmyhouse

Just to check, how would you want your app to work with respect to authentication? Do you want a user to have to enter their FME Server username and password before submitting a request to FME Server or would you want it to work without requiring manual authentication?

If you don't need to have a user enter their name and password, I'd recommend creating a token directly in the FME Server interface first, then using that token directly within your app (instead of using the FMEServer.generateToken call). You can use your own token directly by replacing the server URL and token with your own in the FMEServer.init call.

Hi @LauraAtSafe

 

Okey, I hold my horses on the one then. I´ll keep my eyes open for updates :)

 

Just to clearify, cuz I think that were on different pages.

 

My tought was to use the url to verify the user and therefore give premission to run the workspace. The user+password in the url would be used as a verifier, so that the user would´t have to login thru the FME Server user interface to confirm the access in the used browser. Not to generate the token itself.

If I put a token in the code that is assigned to a specific user, the user could verfiy their premissions thru the URL instead, which not might be possible?

It think that it´s a little to tediously to let the user login thru the interface just to verfy their premissions.


Reply