public void OnAuthorization_RedirectsToAuthorizationRedirectPath_OnlyWhenUserDeniedGrantingPermissions(string requestUrl, string expectedRedirectUrl) { FacebookClient client = MockHelpers.CreateFacebookClient(); IFacebookPermissionService permissionService = MockHelpers.CreatePermissionService(new[] { "" }); FacebookConfiguration config = MockHelpers.CreateConfiguration(client, permissionService); config.AuthorizationRedirectPath = "~/home/permissions"; FacebookAuthorizeFilter authorizeFilter = new FacebookAuthorizeFilter(config); AuthorizationContext context = new AuthorizationContext( MockHelpers.CreateControllerContext(new NameValueCollection { { "signed_request", "exampleSignedRequest" } }, null, new Uri(requestUrl)), MockHelpers.CreateActionDescriptor(new[] { new FacebookAuthorizeAttribute("email") })); authorizeFilter.OnAuthorization(context); ContentResult result = Assert.IsAssignableFrom <JavaScriptRedirectResult>(context.Result); Assert.Equal("text/html", result.ContentType); Assert.Equal( String.Format("<script>window.top.location = '{0}';</script>", expectedRedirectUrl), result.Content); }
public void OnAuthorization_RedirectsToOAuthDialog_ForMissingPermissions() { FacebookClient client = MockHelpers.CreateFacebookClient(); IFacebookPermissionService permissionService = MockHelpers.CreatePermissionService( new[] { "" } ); FacebookConfiguration config = MockHelpers.CreateConfiguration( client, permissionService ); FacebookAuthorizeFilter authorizeFilter = new FacebookAuthorizeFilter(config); AuthorizationContext context = new AuthorizationContext( MockHelpers.CreateControllerContext( new NameValueCollection { { "signed_request", "exampleSignedRequest" } } ), MockHelpers.CreateActionDescriptor( new[] { new FacebookAuthorizeAttribute("email", "user_likes") } ) ); authorizeFilter.OnAuthorization(context); ContentResult result = Assert.IsType <ShowPromptResult>(context.Result); Assert.Equal("text/html", result.ContentType); Assert.Equal( "<script>window.top.location = 'https://www.facebook.com/dialog/oauth?redirect_uri=example.com';</script>", result.Content ); }
public static FacebookConfiguration CreateConfiguration( FacebookClient client = null, IFacebookPermissionService permissionService = null ) { FacebookConfiguration config = new FacebookConfiguration(); if (client == null) { config.ClientProvider = new DefaultFacebookClientProvider(config); config.AppId = "DefaultAppId"; config.AppSecret = "DefaultAppSecret"; } else { Mock <IFacebookClientProvider> clientProvider = new Mock <IFacebookClientProvider>(); clientProvider.Setup(cp => cp.CreateClient()).Returns(client); config.ClientProvider = clientProvider.Object; config.AppId = client.AppId ?? "DefaultAppId"; config.AppSecret = client.AppSecret ?? "DefaultAppSecret"; } config.PermissionService = permissionService ?? new DefaultFacebookPermissionService(config); return(config); }
public static FacebookConfiguration CreateConfiguration(FacebookClient client = null, IFacebookPermissionService permissionService = null) { FacebookConfiguration config = new FacebookConfiguration(); if (client == null) { config.ClientProvider = new DefaultFacebookClientProvider(config); config.AppId = "DefaultAppId"; config.AppSecret = "DefaultAppSecret"; } else { Mock<IFacebookClientProvider> clientProvider = new Mock<IFacebookClientProvider>(); clientProvider.Setup(cp => cp.CreateClient()).Returns(client); config.ClientProvider = clientProvider.Object; config.AppId = client.AppId ?? "DefaultAppId"; config.AppSecret = client.AppSecret ?? "DefaultAppSecret"; } config.PermissionService = permissionService ?? new DefaultFacebookPermissionService(config); return config; }