Silverlight app for select windows users - c#

I have a simple silverlight application hosted on a corporate network. However I want to allow access to this website to few select NT users and restrict the rest. How do I configure it?
Also would such a configuration work for out of browser as well?

you should enable the Integrated windows authentication in the IIS web site or virtual directory configuration. After that in any moment you can take the User.Identity and User.Principal objects and cast them to WindowsIdentity and WindowsPrincipal and check if current user is in a certain role ( aka in a windows group ) or his/her username...
about out of the box I don't know because I have never tried it but you could surely test it once you have a label showing current user name in your SL User Interface, checking if the functionality is the same in the browser or out of browser. Hope this helps...

There are several things you can do.
1) Restrict access to the web services this is calling into - Davide's answer covers this nicely.
2) Restrict access to thw website where the SL app exists, which is easy to do with ASP.NET and the built-in support for Windows Authentication via a MembershipProvider. This way, a user can't even load the HTML page hosting the Silverlight app if they're not in the right role. This would also prevent them from installing the app as Out of Browser, as they can never get to it in the first place.
3) In the OOB mode of the app (when Application.Current.IsRunningOutOfBrowser is true), at startup call into a web service that verifies the user is in the right role - if they're not, the app could simply diplay a "not authorized" visual and not show the real app functionality.
This way, if the user ever was in the role and installed the app OOB, but then lost that permission, they'd still not be able to use the app.
As to implementation of all this, I suggest looking at WCF RIA Services. It has great authentication/authorization support that should simplify implementing this, even if you don't want to use RIA Services for data access for whatever reason (though I recommend that as well, it helps hide a lot of the async complexity of Silverlight data access).

Related

Register desktop application

I am working on a desktop application that gives a desktop tray icon notification when a new pull request is created that requires your attention.
I have developed the application entirely using a public access token for my account. Now I have got to the point where other users need to be able to use the application, I am required to implement OAuth 2.0 authentication.
However, VSO's application authentication assumes my application is a web app and asks me for details that I cannot provide (and aren't even relevant).
How can I get an app id so other users can use my application?
I'm not sure if I'm misunderstanding the whole concept. This is the link I am using: https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/oauth
There is no way to do this for now:
Right now, Visual Studio Team Services only support the web server
flow, so there's no supported way to implement OAuth for Visual Studio
Team Services from an app like a phone app, since there's no way to
securely store the app secret.
As an alternative way, you can use Basic Authentication and ask your users enable "Alternate authentication credentials" and then use the alternative credential to authenticate to VSTS API.

How to authenticate user with form authentication in Windows Desktop Application

I have done some work in Asp.NET, and i am quite used with user authentication using FormAuthentication
Now I am working on a desktop application and i want to have something like above in windows form application, I want to create and authenticate users by using the application database or xml whatever it is like i have done it in Asp.NET. So far did not any way to achieve this like i want to.
Any help would be great!
A Windows desktop application is nothing like an ASP.NET web application.
You cannot call the different forms separately.
(well you can hack the application, but if you do that, you can just as well remove any password protection)
Hence forms authentication does not make any sense.
You can create a login window as startup window, and check username and password against the database.
And that's about it.
It's a Windows application, you don't need membership provider, forms cookie ticket, etc. because unlike HTTP, Windows desktop applications are not stateless.
PS: If you do a WinForms application, make the login via ActiveDirectory authentication.
There is no point in using FormsAuthentication with Windows applications. What you can do is to use Membership, MembershipUser and Roles classes. All you need to do is to configure Membership and Roles providers in app.config.
FormsAuthentication does not actually authenticate your users. If you call Authenticate on FormsAuthentication you will see that it is obsolete method and that Membership.ValidateUser is used instead.
One drawback of these functionalities is that they are part of System.Web namespace which means that you have to use Web functionality inside of your Windows application. But if it can get the job done and fulfills the requirements, then go with it.

how can i authenticate the whole computer instead of web browser?

For the past 2 years we have created 3 desktop application and 2 admin section(web) for one of my client.
Every application uses its own authentication process.
I have merged the authentication process for web in single unit.
But the client wants to have one screen for getting authenticated on desktop application as well as on website.
he also want to use different browser and the username /password should be asked only once irrespective of browser opend.
I tried to use cookies for web. but every browser has got its own cookies.
Can any one suggest how can i authenticate a user for the whole computer so that authentication information is available to desktop application as well as to website irrespective of the browser being used?
Edit: As suggested by joe using windows authentication is not possible in my case.
So i created one more table with following column
ip,userid,authenticatedat
when ever a user is authenticated i insert its ip,userid, and time in table.
when ever a non authenticate user comes first i look in the table if the ip is present and authenticatedat is within 30 min i assume user is authenticated and set the session/variable with data required.
This i have checked and found it is working .
I have found this is not secure.
Windows authentication is the only way I know of doing this. Assuming your users are on a domain you control, then their Windows credentials would validate them, and they wouldn't ever need to enter a username and password.
Outside of that, I can only think of hacky dirty methods of making this happen. You could install a single authentication service on their machine which is available to connect to remotely from other applications - those apps would call your service, and that service would authenticate the user and pass an authentication token back. Easy enough for Windows apps, but making that work on a web app wouldn't be fun. Your web server wouldn't be able to talk to this service, so you'd have to rely on the client javascript talking to the service and retrieving a token or hash, and then the javascript passing this on to the web server.
Anything you put on a local machine, you have to assume the user can reverse engineer and manipulate, so if you need real security, I doubt you'll find a solution. Best bet is just to make the user log in every time you need to, and have your authentication/authorization code on your web service layer.

Windows authentication in SilverLight Application (not Silverlight Business Application)

I am trying to add Windows authentication to an existing website that I have created. All information that I have read regarding using Windows authentication in silverlight requires that you start with the Silverlight Business Applicaion template instead of the Silverliight application template. I already have a website that I started writing using the Silverlight Application template. How can I add windows authentication to this existing website?
If your application is hosted in IIS and this is a intranet site, you just need to set the application in IIS authentication method to Windows Authentication, then when the client tries to load the SL App a 401 challenge will trigger asking the user to enter in his/hers credentials. You can also set IE to pass with windows credentials to the server when the site is loaded.
I have had spent quite a bit of time tweaking various properties to get the right functionality that i am looking for (especially with machine names being fully qualifies or not) but basically that's one thing to keep in mind when debugging this is that machines names play a role in how the server interprets a client trying to access the server.

How to Elevate Role in ASP.net From anonymous to windows auth?

I have a few websites which allow both anonymous and window auth users at the same time. Basically if you hit the site with IE or Webkit based browsers on a windows system, the server instantly recognizes your active directory user and group.
In the past I've provided a link to a windows auth only page which allows the current user to login, or bounce back to where they started.
I find the management of this kind of frustrating as I need to make certain that IIS has the correct security settings for that single page after every deployment.
Is there a better way for me to allow a user to elevate from anon to authenticated?
There is no other way to do that elevation automatically. The server can't know that the current user is a Windows user and elevate them, or automatically redirect them to the Windows auth only page. On the other hand, if every user will get through the Windows auth only page, all of them which are not inside the domain will see the challenge/response dialog box (user + password).
As for the management part of making sure that this special page has the correct security settings, you can (and should) automate the check somehow. For example, by querying the IIS metabase for that setting when the application starts (in Global.asax) and if the setting is not there, log it as an email message or so.
Personally I prefer a different attitude - a special "integration/deployment" page which contains a series of tests against my application so I can make sure everything's set up correctly on the server, i.e. NTFS write permissions to certain folders, availability of the SMTP server set in web.config to send emails through, etc.
Note: You're using Windows authentication along with anonymous access. Just keep in mind that if you consider implementing Forms Authentication in the future, a misarchitecture (I don't know if by design or due to a flaw) of IIS 7 does not allow you to set the app to be Forms Authentication and set one specific page to be Windows Authentication. The override just doesn't work and it's very frustrating.
Good luck!
OK, I figured out a fairly nice way to do this...however it's not as elegant as I had hoped since it doesn't work across applications.
Basically, if you create a single page within your Anon + Integrated Auth IIS6 website or virtual directory, let's call it auth.aspx, then you can use this page to prompt authentication.
Go into IIS settings and specify that auth.aspx is Integrated Auth ONLY (no anon). Then create a hidden iframe somewhere on your page. I then created a simple JavaScript action to update the src attribute of the iframe to the auth.aspx page. This forces the browser to try and authenticate using NTLM. Once you enter valid credentials you've successfully elevated your current user beyond the generic anonymous user.
One final touch was to then include a Response.Redirect into the auth.aspx which reloads the current page. Assuming your ASP.net session tokens are set correctly, the page will reload and the user will be authenticated.

Categories

Resources