{"action":"closed","issue":{"url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/738","labels_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/738/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/738/comments","events_url":"https://api.github.com/repos/Azure/azure-mobile-services/issues/738/events","html_url":"https://github.com/Azure/azure-mobile-services/issues/738","id":92998923,"number":738,"title":"Facebook login and access_denied","user":{"login":"jakiiskinen","id":6151805,"avatar_url":"https://avatars.githubusercontent.com/u/6151805?v=3","gravatar_id":"","url":"https://api.github.com/users/jakiiskinen","html_url":"https://github.com/jakiiskinen","followers_url":"https://api.github.com/users/jakiiskinen/followers","following_url":"https://api.github.com/users/jakiiskinen/following{/other_user}","gists_url":"https://api.github.com/users/jakiiskinen/gists{/gist_id}","starred_url":"https://api.github.com/users/jakiiskinen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakiiskinen/subscriptions","organizations_url":"https://api.github.com/users/jakiiskinen/orgs","repos_url":"https://api.github.com/users/jakiiskinen/repos","events_url":"https://api.github.com/users/jakiiskinen/events{/privacy}","received_events_url":"https://api.github.com/users/jakiiskinen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Azure/azure-mobile-services/labels/Area-Javascript","name":"Area-Javascript","color":"5319e7"},{"url":"https://api.github.com/repos/Azure/azure-mobile-services/labels/Area-Managed","name":"Area-Managed","color":"5319e7"},{"url":"https://api.github.com/repos/Azure/azure-mobile-services/labels/Resolution-External","name":"Resolution-External","color":"cccccc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-04T10:17:07Z","updated_at":"2015-12-30T22:37:20Z","closed_at":"2015-12-30T22:37:20Z","body":"There is an issue with Facebook login on Windows Phone 8.1. When the user selects Cancel on the app permission page, all subsequent login attempts fail.\r\n\r\nThe issue can be reproduced as follows:\r\n1) Call MobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.Facebook)\r\n2) In Facebook login page, enter credentials, and on next page, when Facebook asks the user to authorize the application, select Cancel\r\n3) When the control returns to the application, in OnActivated method the ResponseData in  WebAuthenticationBrokerContinuationEventArgs argument does not contain a token string. The response is something like this: https://abc.azure-mobile.net/login/done#error=Error%3A%20access_denied%3A%20Permissions%20error\r\n\r\nAuthenticationBroker.GetTokenStringFromResult called by MobileServiceClient.LoginComplete method then throws an InvalidOperationException. AuthenticationBroker.AuthenticationComplete leaves pendingLoginTask static member in Pending state, and all subsequent calls to LoginAsync will result in an error \"Authentication is already in progress.\"\r\n\r\nWe have fixed this for our own purposes by changing the AuthenticationBroker.AuthenticationComplete as described below. Feel free to use this change if it seems OK.\r\n\r\n```\r\npublic void AuthenticationComplete(WebAuthenticationResult result)\r\n{\r\n\tif (pendingLoginTask == null)\r\n\t{\r\n\t\tthrow new InvalidOperationException(\"Authentication has not been started.\");\r\n\t}\r\n\r\n\tif (result.ResponseStatus != WebAuthenticationStatus.Success)\r\n\t{\r\n\t\tstring message;\r\n\t\tif (result.ResponseStatus == WebAuthenticationStatus.UserCancel)\r\n\t\t{\r\n\t\t\tmessage = \"Authentication was cancelled by the user.\";\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tmessage = string.Format(CultureInfo.InvariantCulture,\r\n\t\t\t\t\t\t\t\t\t\"Authentication failed with HTTP response code {0}.\",\r\n\t\t\t\t\t\t\t\t\tresult.ResponseErrorDetail);\r\n\t\t}\r\n\t\tpendingLoginTask.SetException(new InvalidOperationException(message));                \r\n\t}\r\n\telse\r\n\t{\r\n\t\tstring tokenString;\r\n\t\ttry\r\n\t\t{\r\n\t\t\ttokenString = GetTokenStringFromResult(result);\r\n\t\t}\r\n\t\tcatch (InvalidOperationException)\r\n\t\t{\r\n\t\t\t//If the user selects Cancel in Facebook permission request dialog, token stríng is not present in the response\r\n\t\t\tpendingLoginTask = null;\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tpendingLoginTask.SetResult(tokenString);\r\n\t}\r\n\tpendingLoginTask = null;            \r\n}\r\n```"}}