• Stars
    star
    394
  • Rank 106,690 (Top 3 %)
  • Language
    C#
  • Created almost 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OAuth2 client implementation for .NET

OAuth2

Build status NuGet Version

OAuth2 is a library for user authentication using third-party services (OAuth/OAuth2 protocol) such as Google, Facebook and so on.

Current Version and Status

Current version is 0.10.x Status is "release candidate" - despite we already have several real life projects built with usage of this library, we will change status to "stable" only after comprehensive set of acceptance tests is ready and runs successfully.

Standard Flow

Following are the steps of standard flow:

  • generate login URL and render page with it
  • define callback which will be called by third-party service on successful authentication
  • retrieve user info on callback from third-party service

Usage Example

Several simple steps to plug in the library into your app:

Install OAuth2 package via NuGet

Install-Package OAuth2

Your action function that needs to generate and redirect to the third-party service will look like

public ActionResult GoogleLogin()
{
  var redirectUri = new Uri(Url.Action("GoogleLoginCallBack", "Account", null, protocol: Request.Url.Scheme));
  var googleClient = new GoogleClient(new RequestFactory(), new OAuth2.Configuration.ClientConfiguration
  {
    ClientId = auth.ClientId?.Trim(),
    ClientSecret = auth.ClientSecret?.Trim(),
    RedirectUri = redirectUrl,
    Scope = "profile email"
  });
  return Redirect(googleClient.GetLoginLinkUri("SomeStateValueYouWantToUse"));
}

Finally the action that handles the callback will look like this :

public ActionResult GoogleLoginCallBack()
{
  var code = Request.QueryString["code"];
  var redirectUri = new Uri(Url.Action("GoogleLoginCallBack", "Account", null, protocol: Request.Url.Scheme));
  var googleClient = new GoogleClient(new RequestFactory(), new OAuth2.Configuration.ClientConfiguration
  {
    ClientId = auth.ClientId?.Trim(),
    ClientSecret = auth.ClientSecret?.Trim(),
    RedirectUri = redirectUrl,
    Scope = "profile email"
  });

  try
  {
    userInfo = oauth.GetUserInfo(new NameValueCollection() { { "code", code } });
  }
  catch(Exception ex)
  {
    return RedirectToAction("LoginError", new {error = ex.Message});
  }

  // do your validation and allow the user to proceed
  if (SignInManager.IsUserValid(userInfo.Email))
  {
    SignInManager.Login(userInfo.Email);
    return RedirectToAction("Index", "Home", new {error = ex.Message});
  }
  return Redirect(googleClient"LoginError", new {error = "User does not exists in the system"});
}

Supported Services

  • Asana
  • DigitalOcean
  • Facebook
  • Foursquare
  • GitHub
  • Google
  • Instagram
  • LinkedIn
  • MailRu
  • Odnoklassniki
  • Salesforce
  • Spotify
  • Todoist
  • Twitter
  • VK (Vkontakte)
  • Visual Studio Team Services (VSTS)
  • Windows Live
  • Yahoo
  • Yandex
  • Uber

Goals

Before I started working on this project I considered available solutions: several ones were found, but I wasn't satisfied with results:

  • some of them were too complex for such simple task as authentication via OAuth2
  • some - didn't have usage examples or documentation

So, I decided to implement this library striving to achieve following goals:

  • simplicity in usage - so even newbie can just call couple of methods and receive expected results
  • well-documented, testable and tested (!) code - current coverage (according to NCrunch) is greater than 80%, several acceptance tests are also implemented (SpecFlow + WatiN)
  • flexible, transparent and easily understandable design, so library can be used both by people who need only certain parts and fine-grained control over them and by people who want just plug it in and immediately receive expected result
  • self-education :) - it was interesting to see how OAuth2 works

Dependencies

This library is dependent on:

Contributors

  • Constantin Titarenko (started development, defined library structure, released initial version)
  • Blake Niemyjski (helped a lot to maintain the project, currently (since 2015) - top maintainer)
  • Andriy Somak (helped a lot with improvements on configuration as well as with extending list of supported services by implementing their clients)
  • Sascha Kiefer (simplified extending library with own provider implementations, added GitHub client)
  • KrisztiΓ‘n PΓ³cza (added LinkedIn (OAuth 2) client)
  • Jamie Houston (added a Todoist client)
  • Sasidhar Kasturi (added Uber, Spotify, Yahoo)
  • Jamie Dalton (added Visual Studio Team Services)

Acknowledgements

Many thanks to JetBrains company for providing free OSS licenses for ReSharper and dotCover - these tools allow us to work on this project with pleasure!

Also we glad to have opportunity to use free Teamcity CI server provided by Codebetter.com and JetBrains - many thanks for supporting OSS!

JetBrains

OAuth2 optimization would never be so simple without YourKit .NET profiler! We appreciate kind support of open source projects by YourKit LLC - the creator of innovative and intelligent tools for profiling .NET YourKit .NET Profiler and Java applications YourKit Java Profiler.

Roadmap

  • Implement more acceptance tests
  • Increase code coverage by finalizing unit tests

License

The MIT License (MIT) Copyright (c) 2012-2013 Constantin Titarenko, Andrew Semack and others

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

fast-exif

Fast EXIF extraction without reading whole file into memory.
TypeScript
54
star
2

knex-filter

Declarative filtering for knex.
JavaScript
12
star
3

worque

AMQP-based work queue.
JavaScript
11
star
4

eta

Estimated time to arrival.
JavaScript
9
star
5

gulp-dotify

Gulp plugin for precompilation of doT templates.
JavaScript
8
star
6

TestDataFactory

Library for effortless generation of (not only) POCO objects.
C#
7
star
7

ClientManager

Lite CRM
JavaScript
7
star
8

ukrstemmer

Stemmer for Ukrainian language (works good enough for Russian language as well).
JavaScript
6
star
9

totlog

The only true log
JavaScript
4
star
10

fix-phone

Validate and format phone number, or return nothing, if such phone is not valid.
JavaScript
4
star
11

korrekt

JavaScript
3
star
12

buhoi

Because drunk people can create web apps too.
JavaScript
3
star
13

evque

AMQP-based event bus.
JavaScript
3
star
14

fast-video-metadata

Fast metadata extraction without dependencies (e. g. usage of spawned ffmpeg, exiftool, etc)
TypeScript
3
star
15

joba

Simple task (job) scheduler (manager).
JavaScript
3
star
16

buhoi-migrator

PostgreSQL migration tool
JavaScript
2
star
17

Cqrsnes

CQRS And Event Sourcing Custom Infrastructure
C#
2
star
18

logstash-udp

Your log messages go to logstash UDP input (almost) without any overhead.
JavaScript
2
star
19

HandyToolsAndExtensions

A set of handy tools and extensions for .NET (C#).
C#
2
star
20

generator-erma

An Express-REST-Marionette web application generator for Yeoman.
CoffeeScript
2
star
21

KenoRobot

Keno (Lottery) Player Model
C#
2
star
22

kmex

Like knex, but for MongoDB
JavaScript
2
star
23

opixml

Opinionated XML generator and parser
JavaScript
2
star
24

sqlcut

JavaScript
2
star
25

xstruct

Set of tools for structured data extraction from web.
JavaScript
2
star
26

ASF

Tools for interaction with ASF media file format.
C
2
star
27

MilkPlant

C#
2
star
28

Pathman

Pathman is a small 3D game that was written as a solution for qualifying round of XPN (Extreme Programming Night, http://xpn.com.ua).
C++
2
star
29

json_encode

Do JSON.srtringify like PHP does json_encode (useful if you need to handle Unicode symbols like it's done in PHP)
JavaScript
2
star
30

qpg

Q-style PG (https://github.com/kriskowal/q, https://github.com/brianc/node-postgres)
JavaScript
1
star
31

tsviz

Typescript source code visualization using UML+ diagrams
TypeScript
1
star
32

test8

JavaScript
1
star
33

buhoi-ui

JavaScript
1
star
34

taskr

Simplest task management module.
JavaScript
1
star
35

flou

Simple construction of complex flows.
JavaScript
1
star
36

ong

Oh no! Globals!
JavaScript
1
star
37

butcher

Simple node.js deployments triggered by push to GitHub.
JavaScript
1
star
38

mqu

Job and event distribution built on top of RabbitMQ.
JavaScript
1
star
39

bubble-chart

Bubble chart based on D3 library.
1
star
40

buhoi-client

Client side part of buhoi framework.
JavaScript
1
star
41

wrong

Another JS object validator with focus on simplicity.
JavaScript
1
star
42

generator-libco

"Library in CoffeeScript" generator.
JavaScript
1
star
43

sqlcut-mysql

JavaScript
1
star
44

nofail

Failover version builder for `fn(array)`. Promise-based.
JavaScript
1
star
45

sqlcut-mssql

JavaScript
1
star
46

eslint-plugin-func-call

Eslint plugin to control function call code style
JavaScript
1
star
47

wachter

JavaScript
1
star
48

bex

Set of util functions to quickly "bootstrap express" application.
JavaScript
1
star
49

Market

This solution will contain a set of projects with a different implementations of simplistic model of market. The goal is to compare how different architectural and technological approaches help us to achieve greater results with lower investments.
JavaScript
1
star
50

fcdb

File-backed collection in-memory storage
JavaScript
1
star
51

sqlcut-pg

JavaScript
1
star