File | Date | Author | Commit |
---|---|---|---|
examples | 2016-09-17 |
![]() |
[6c797c] v1.12 |
src | 2016-09-17 |
![]() |
[6c797c] v1.12 |
.gitignore | 2016-09-17 |
![]() |
[6c797c] v1.12 |
CHANGELOG.md | 2016-09-17 |
![]() |
[6c797c] v1.12 |
Guide Nemiro.OAuth.chm | 2015-03-19 |
![]() |
[56894d] v1.9 |
LICENSE | 2015-01-04 |
![]() |
[9288c8] v1.6 |
README.md | 2016-07-12 |
![]() |
[469116] v1.11 |
README.ru.md | 2016-07-12 |
![]() |
[469116] v1.11 |
preview.png | 2015-03-19 |
![]() |
[56894d] v1.9 |
Nemiro.OAuth is a class library for authorization via OAuth protocol in .NET Framework.
The library provides mechanisms for implementing OAuth clients, and also contains a ready-to-use clients for popular websites.
Nemiro.OAuth is licensed under the Apache License Version 2.0.
To install Nemiro.OAuth, run the following command in the Package Manager Console:
PM> Install-Package Nemiro.OAuth
Less code, more functionality!
1. Create an application at the OAuth provider site.
2. Use these credentials for registration of an OAuth client in your project.
For example, Facebook:
C#
OAuthManager.RegisterClient
(
"facebook",
"1435890426686808",
"c6057dfae399beee9e8dc46a4182e8fd"
);
Visual Basic .NET
OAuthManager.RegisterClient _
(
"facebook",
"1435890426686808",
"c6057dfae399beee9e8dc46a4182e8fd"
)
3. Create a page to handle the callback. And add code to obtain user data with external server.
For example:
C#
public partial class ExternalLoginResult : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var result = OAuthWeb.VerifyAuthorization();
Response.Write(String.Format("Provider: {0}<br />", result.ProviderName));
if (result.IsSuccessfully)
{
var user = result.UserInfo;
Response.Write(String.Format("User ID: {0}<br />", user.UserId));
Response.Write(String.Format("Name: {0}<br />", user.DisplayName));
Response.Write(String.Format("Email: {0}", user.Email));
}
else
{
Response.Write(result.ErrorInfo.Message);
}
}
}
Visual Basic .NET
Public Class ExternalLoginResult
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim result As AuthorizationResult = OAuthWeb.VerifyAuthorization()
Response.Write(String.Format("Provider: {0}<br />", result.ProviderName))
If result.IsSuccessfully Then
Dim user As UserInfo = result.UserInfo
Response.Write(String.Format("User ID: {0}<br />", user.UserId))
Response.Write(String.Format("Name: {0}<br />", user.DisplayName))
Response.Write(String.Format("Email: {0}", user.Email))
Else
Response.Write(result.ErrorInfo.ToString())
End If
End Sub
End Class
4. Get the address for authentication and redirect the user to it.
C#
string returnUrl = new Uri(Request.Url, "ExternalLoginResult.aspx").AbsoluteUri;
OAuthWeb.RedirectToAuthorization("facebook", returnUrl);
Visual Basic .NET
Dim returnUrl As String = New Uri(Request.Url, "ExternalLoginResult.aspx").AbsoluteUri
OAuthWeb.RedirectToAuthorization("facebook", returnUrl)
5. Enjoy!