AnsweredAssumed Answered

AbstractWebscript cannot redirect without prompting

Question asked by akring on Nov 23, 2015

I working on an amp which implements the following behaviour:

<li>An already logged in user clicks a custom (folder-browse) action on a folder in the document library for a given site</li>
<li>This will take him to a third party server where he receives an OAuth2 token</li>
<li>This OAuth2 token is given back to Alfresco by having the third party server call back to an share page using an URL like this:…</li>
<li>The share page then calls an AbstractWebscript using a url like this:…</li>
<li>The token is then stored by the AbstractWebscript</li>
<li>The AbstractWebscript should then redirect the user to a page on the share side</li>

But the user is presented with the standard share login prompt (even though he was already logged in before the first step in the list above), before the redirect takes place?

And if I comment out the two redirect lines in the Java class below and replace them with the line


then the word "test" is written fine in the browser without any Alfresco login prompts?

The webscript looks something like this:

public class StoreOAuth2Token extends AbstractWebScript {

   OAuth2CredentialsStoreService oAuth2CredentialsStoreService;
   public void execute(WebScriptRequest req, WebScriptResponse resp) throws IOException {

                … code to store token and other details …

      // resp.getWriter().write("test");
      resp.setHeader("Location", "" + URLEncoder.encode(nodeRefStr, "UTF-8") + "&finalRedirect=" + URLEncoder.encode(finalRedirect, "UTF-8") + "&fragment=" + URLEncoder.encode(fragment, "UTF-8"));
   public void setoAuth2CredentialsStoreService(OAuth2CredentialsStoreService oAuth2CredentialsStoreService) {
      this.oAuth2CredentialsStoreService = oAuth2CredentialsStoreService;

Any ideas on how to fix this?