CredentialCache with IIS vs personal development server - c#

I have a webservice that I am testing. When I use the personal asp.net webserver, the one with the random port everything works fine. It uses my credentials when I pass DefaultCredentials to an ssrs server to run a report.
When I tried to move it to my local IIS server, the DefualtCredentials UserName is blank and the ID that gets pass to the SSRS server is ASPNET.
I turned off Annon access and only Integrated Windows Authentication is on.
My local IIS is 5.1, so it doesn't have application pools as a separate object.
In the web.config authentication is set
<authentication mode="Windows" />
Thanks in advance.
UPDATE
I do have the
<identity impersonate="true" />
now, but my problem is trickier then originally stated.
The outer webservice calls SSRS webservice and now it works fine in the browser.
But when I call the outer webservice from within SSIS, it does not work, when I step through the code the call to the outer webservice occurs but when I make the call to SSRS i get a 401 Authentication error.
I have valid credentials in the HTTP Manager. I have the package protection level at EncryptSensitiveWithUserKey.
Again if I call the outer webservice from a personal ASP.net webserver, even the SSIS works fine. I just have to download the wsdl every time because the port changes and then I have to re-setup the webservice task. I am concern when I go to production.
(I have yet to run a test from code to see how the webservice acts)
UPDATE 2
Again the webservice works in IE, but not in SSIS nor Firefox even when I supply my credentials when I hit the webservice
I know I am getting authenticated properly because
User.Identity.Name
returns my login name in the webservice, but when I assign defaultCredentials to the reporting service service it still gives me 401 error. I even tried to impersonate the log in that I was logged in as
Dim win As System.Security.Principal.WindowsIdentity = CType(User.Identity, System.Security.Principal.WindowsIdentity)
Dim context As System.Security.Principal.WindowsImpersonationContext = win.Impersonate()
reportService.Credentials = System.Net.CredentialCache.DefaultCredentials

This is the answer I received from Microsoft.
It was my pleasure to discuss your issue over the phone littler earlier. As I was saying that HTTP connection manager does not support Windows Authentication, please have a look at the article at: http://msdn.microsoft.com/en-us/library/ms140114.aspx
Important
The HTTP connection manager supports only anonymous authentication and basic
authentication. It does not support Windows Authentication.
So, at this point using Script Task to call the Web Services would be an option, however you mentioned that there will be a challenge of moving the package to QA to UAT etc. I agree with you that managing the URL in the proxy class is a challenge.
Please let me know if you have further questions.
Now even this is not true because I showed the gentleman from Microsoft that our web service did require Windows Authentication but what is not working is known as the “double-hop”. That is the credentials do not get passed to the SSRS server.

Related

403 Forbidden when using client managed authentication on Azure App Service

I've been working on a multi-app project for a few months now using Azure App Service for my database and ADD B2C for authentication. There are three applications in this project: an admin WPF app, a client web app, and an employee WPF app. All three applications use client managed authentication with my B2C tenant by getting a token from B2C and using that token to login to the App Service database. Everything has been working fine until seemingly overnight I am no longer able to authenticate with the app service. I have no problem displaying the B2C login screen and getting an access token as a result of the authentication, but when I package the token in a JObject and call the 'mobileServiceClient.LoginAsync()' function, all I get back is a 403 "forbidden" error.
First I tried seeing if all three projects were affected, which they are. I then tried rolling back to my last commit. Still the same thing. I then tried re-cloning to see if there was any little quirk with still the same results. Because I know my Azure resources have not hit their limits, I then tried making a completely separate WPF project and I made a table on the app service that allows anonymous access. After setting "Action to take when request is not authenticated" to "Allow anonymous access" on the app service, I was able to read and write to the anonymous table without issue. I then tried to have this new project authenticate the same way the others have been only to get the same 403 error. After checking all of this I can say I'm almost completely sure that there is no issue with the client applications and the issue has to be on the server side.The most confusing part for me is that aside from adding a new table to the database, I haven't changed a single thing server side. I've checked out both the B2C tenant and the authentication settings on the app service but nothing seems to be different than before I was experiencing this problem. Investigating a little bit more in the app service, I tried to find some JS code that handles authentication to see if I could find any useful information using the console output. I did not find any code, but I did find out the console outputs PID[31680] Information Sending response: 403.76 Forbidden whenever a client tries to authenticate.
Additional information that might help is that my request header timestamp is correct. I know from research that Azure only allows a 15 minute variance for incoming requests from its time.
Any help or suggestions for solving this issue would be greatly appreciated! Thanks!

Setting up Kerberos 2 hop authentication between Web App and API

I am using Windows Server 2018, IIS 10 and my web application targets .Net Framework 4.5.1. My API, I built using .Net Core 2.1 and Visual Studio 2017. Both the website and the API use windows authentication.
I used this person's tutorial to try and setup Kerberos two hop authentication (https://blogs.msdn.microsoft.com/surajdixit/2018/02/07/kerberos-configuration-manager-for-internet-information-services-server/).
Steps I've taken and tried,
Set the app pool to run under a custom domain account.
Added an SPN to the domain account that points to the website DNS address in the domain
Switched the app pool to classic mode
Turned on Windows Authentication and Impersonation for the website.
Had system admin grant the custom domain account delegation rights.
The current problem I am facing, is now that I made all these modifications to the app pool and the website in IIS, when I try to connect to the website, it prompts for credentials, which shouldn't happen as it should authenticate me through my windows domain account, when I input the credentials, it just refreshes with the prompt for credentials again. When running locally everything works correctly and the HttpClient in my web application successfully calls out to the API.
I have spent hours on this and would appreciate any help. I am out of ideas.
So after trying multiple walkthroughs and working with other developers, I found that the issue was both applications, the web app and the api, running on the same server. Once I moved the api to it's own dedicated server, I had no need for impersonation and was able to just load the user profile credentials from the app pool as it was running as a domain account. HttpClient and WebClient objects were both successful then at making requests to the api by setting UseDefaultCredentials = true.
If anyone ever has this issue, try hosting your api on a different server. I spent a few days thinking it was something I had done wrong in configuring things, and in the end, it was just where I was hosting the applications.
There may be a way to make this work successfully on the same server, but I was unable to make it work. Maybe someone else who is more experienced can add to this post to help show how to do this on the same server. Happy coding everyone.

Azure Active Directory Authentication with Azure Mobile Services Failed

I followed this Microsoft Azure Mobile Service Authentication Tutorial, to try to add a server authentication function for my Windows Store C# app. However, after completing every step, when I run my app, it showed that the application cannot connect to the service.
I found this useful blog tallking about troubleshooting Azure Authentication issues in Azure Mobile Service. To troubleshoot, I type the link in the firefox web browser: myServiceUrl/login/aad, but I receive the error response:
Authorization has been denied for this request.
I also followed the same tutorial to test with Google Log in. It turns out to work properly. And when I type the link: myServiceUrl/login/google, the web browser directed me to the google log in page, unlike the Unauthorization error message when I type in myServiceUrl/login/aad.
Although google log in works out fine, but it is desired for us to use Azure Active Directory authentication. Could anyone tell us what could possibly be wrong? Any troubleshooting suggestions are also appreciated. Thank you.
The "Application cannot connect to the service" error comes from whenever the Web Authentication Broker in Windows receives an error response from the resource it is trying to reach. There are a couple of issues that can cause this, and I'll try and address the most common ones.
I noticed the tutorial you linked to is for the .NET backend. If you are using the Mobile Services .NET backend, there is an extra step required to configure the AAD server flow, and it's a common cause of the issue being described. In the tutorial, it's under the title "Configure your .NET mobile service for AAD login." On the backend project, you will need to install the Mobile Services .NET Backend Security Extension NuGet package. Then, in WebApiConfig.cs, you will need to include
options.LoginProviders.Remove(typeof(AzureActiveDirectoryLoginProvider));
options.LoginProviders.Add(typeof(AzureActiveDirectoryExtendedLoginProvider));
This allows the runtime to use the server flow in addition to the client flow (leveraging the Active Directory Authentication Library) which was first released with the .NET backend.
Pending that, or in the case of the Node runtime, the next thing to do is check the AAD configuration. In the AAD portal, make sure that your application registration uses your mobile service's /login/aad endpoint for the resource URI. It must match exactly the value provided in the Mobile Services portal. This should also be one of the redirect URIs if you are using the Node backend. For .NET, you would use the /signin-aad endpoint for the redirect URI instead.
You should also check that you have copied the Client ID from the AAD registration and pasted it into the Mobile Services portal's Identity Tab. For completeness, the "Allowed Tenants" field should also be filled out, but I don't believe it is the cause of this issue.
Lastly, if your AAD tenant is federated with ADFS, then there is a wide range of issues that could lead to this. The biggest case comes from the WAB needing to be configured for Enterprise Authentication. This typically only causes problems when the device is domain joined / on the corporate network. That behavior is a known bug for the Mobile Services Windows Store SDK, but there is a workaround available. Glad to provide that if needed.

Adding Web Reference to a secure http web service

I have a WCF client from which i am supposed to communicate to a thirdparty web service whose url and wsdl is disclosed.The third party WebService(.asmx) uses https. All I am doing is trying to add service reference from my dev environment ,but unable to succeed.So i went ahead and used SOAPUI to test the service where i am able to fire a request and got a response.
Is it not possible in VS2010 to add the service reference in order to access the metadata of a HTTPS web service ? Since this is the first time I am using HTTPS ,i would be glad if some one can guide me the right way ?
#Aron :I tried to get the same by using a web browser and i selected proceed anyway option then it takes me to the WSDL page.
I will assume that you are running your development server on your local dev machine. You should check the actual address that the IIS server is setup for. Open up the page in your web browser. You will have a page that asks you if you want to proceed anyway, DONT.
View server certificate.
Here is the GMail certificate. Notice the "issued to:". This means that the certificate is only for https://mail.google.com. If another server tried to use it for another address you would have the same error.
So you want to use whatever is in there as your https://{my issued to}/Webservice.asmx

What type of web service should I put together?

I want to write a web service using Visual Studio. The service needs to support some type of authentication, and should be able to receive commands via simple HTTP GET requests. The input would only be a method call with some parameters, and the responses will be simple status/error codes. My instinct would be to go with an ASP.NET Web Service, but this isn't an option in C# 4.0 and it makes me wonder if I should be using something that's more up-to-date. I've looked into WCF, but it seems like this requires a running application on the client-side - is there a way to query a WCF host by just accessing a URL?
The authentication is also an important piece. Developing my own little authentication system seems like a bad idea - I've read that it's too easy to mess up. What would be the standard way of authenticating with a web service like this?
I'd love to look up all of the specifics on this and learn it myself, but I really don't even know where to begin. Some direction would be greatly appreciated!
For a simple HTTP service that takes commands via GET (you should actually consider using POST...) I would use straight ASP MVC, not a true
'web service'. WCF wants to guide you down the path of SOAP and your clients will curse you forever. RESTful WCF is also an alternative, but it still seem overkill imho.
As for authentication, you have two viable authentication schemes:
Windows Integrated security, which will work only if client is inside intranet or connected with a VPN or DirectAccess solution
HTTP Digest, which is poorly supported by the ASP authentication modes (only support authenticating against a Active Directory forest user base).
With Windows authentication you don't do anything on the server side code, simply mark the the web.config <authentication mode="Windows" />. 'Windows' authentication is understood by most user agents. Is trivial to program clients of your service to use Windows authentication too, simple set the request's Credentials to the current user DefaultCredentials.
With Digest authentication the server will challenge the user agent to authenticate, but the ASP validation unfortunately, as I said, only works for validating a trusted NT domain. The client though does not need to be in the intranet (there is no NTLM SSPI exchange between client and server). Programming a client is faily easy, in .Net simply set the requet Credentials to a properly initialized CredentialsCache:
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri("http://www.contoso.com/"),"Digest", new NetworkCredential(UserName,SecurelyStoredPassword,Domain));
...
request.PreAuthenticate = true;
request.Credentials = myCache;
It is important to reuse the cache between requests, otherwise the client will do two round-trips with each call.
In theory you can also have a third authentication path: full duplex SSL. But the 'trivial' problem of client certificate deployment makes this alternative a dead end for anybody short of a fully pre-installed enterprise PKI.

Categories