0

I have a provider hosted Add-In which looks like that:

https://myhost.com/mycontroller/myaction?SPHostUrl=https://myhost.sharepoint.com/sites/mysite&SPLanguage=en-US&SPClientTag=0&SPProductNumber=16.0.5214.1200&SPAppWebUrl=https://myhost-47c946ab06e988.sharepoint.com/sites/mysite/myapp

In this controller I do the usual OAuth-Permission checks and retrieve the SharePoint-Context using SPTokenhelper

When the user is not authenticated I want to redirect him to the SharePoint/Office365 - login page.

On Office365, the login-page is something like

https://login.microsoftonline.com/login.srf?wa=wsignin1.0&rpsnv=4&ct=1461150045&rver=6.1.6206.0&wp=MBI&wreply=https%3A%2F%2Fmyhost-47c946ab06e988.sharepoint.com%2F_forms%2Fdefault.aspx%3Fapr%3D1&lc=1033&id=500046&client-request-id=1258749d-a0e5-3000-9580-b7f270ccabba

I do not want to hardcode that login-address as this may differ if it is OnPrem instead of Office365. How can I redirect to the Loginpage?

I want to retrieve the right address programmatically and NOT use a hardcoded Url, because this should work on O365 as well as on OnPrem.

  • Have you done code using CSOM to check permission and generate token? – Viraj Gorajia Apr 20 '16 at 11:59
  • Yes. Through CSOM I detect that the user isnt authenticated (SpContext is null). So I know that the user HAS TO login. But not, where he can do that – Ole Albers Apr 20 '16 at 12:04
  • I don't understand " user HAS TO login. But not, where he can do that ". But you can redirect after SPcontext getting null – Viraj Gorajia Apr 20 '16 at 12:13
  • Yes. But where to? That is what I asked: Where to redirect without using hard-coded urls so this works on SP2013 and O365 – Ole Albers Apr 20 '16 at 13:19
  • From where class is called for code ("detect that the user isnt authenticated (SpContext is null)")? – Viraj Gorajia Apr 21 '16 at 6:19
0
public abstract class Controller : ControllerBase, IActionFilter, IAuthenticationFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter, IAsyncController, IAsyncManagerContainer
{ }


public class MyController : Controller
{
    protected override void OnAuthentication(AuthenticationContext filterContext)
    {
        //custom authentication logic
    }

    protected override void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
    {
        //custom authentication challenge logic
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.