Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth with custom oauth provider in MVC 4

I'm writing a simple web application in MVC 4, and I want to OAuth with Trello so that I can ask a user to log-in with their trello details and then see some of their cards.

Can anyone provide information about creating a custom oauth provider to support non-out of the box oauth providers? From what I can see, I think I need to create a custom Oauth provider (subclass IAuthenticationClient and use that) - is that right?

like image 907
Matt Roberts Avatar asked Dec 19 '12 13:12

Matt Roberts


People also ask

Is OAuth and autho same?

OAuth 2.0 is a protocol that allows a user to grant limited access to their resources on one site, to another site, without having to expose their credentials. Auth0 is an organisation, who manages Universal Identity Platform for web, mobile and IoT can handle any of them — B2C, B2B, B2E, or a combination.

What is AuthConfig Cs in MVC?

When you create an MVC 4 web application with the Internet Application template, the project is created with a file named AuthConfig. cs in the App_Start folder. The AuthConfig file contains code to register clients for external authentication providers.

What is OAuth in MVC?

OAuth is an open standard for authorization. OAuth provides client applications a "secure delegated access" to server resources on behalf of a resource owner. It specifies a process for resource owners to authorize third-party access to their server resources without sharing their credentials (from the Wikipedia).

What is oath2?

OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user.


1 Answers

Okay, I spent the 11 hours since my comment writing a custom oAuth class for SO. Tomorrow I get to do one of sales force. I'm not excited.

Here's what I did:

  1. Create a DataContract class for your expected Json/Xml. I went ahead and implemented everything that SO returns, but if you're only doing authorization you can probably cut it down to an ID and DisplayName.

  2. Create a class that extends OAuth2Client from DotNetOpenAuth.AspNet.Clients. Use the DotNetOpenAuth GitHub page for examples. This is the longest, and most painful step, especially if your json serialization is rusty.

  3. Open up /App_Start/AuthConfig.cs and enter OAuthWebSecurity.RegisterClient(new YourClass(Your, Initalization, Params), "The Name You Want to Show Up On Your oAuth Login Button", ExtraDataIfYouNeedIt; somewhere in the RegisterAuth() section. I haven't established what the ExtraData param is for, but I didn't need it in my case. Hopefully you won't need it in yours.

Edit: Updated github link.

like image 78
Billdr Avatar answered Oct 26 '22 22:10

Billdr