All Projects → waqaskhan540 → Identityserverexternalauth

waqaskhan540 / Identityserverexternalauth

A solution for exchanging external (Facebook,Google,Twitter etc) tokens with IdentityServer access token.

Projects that are alternatives of or similar to Identityserverexternalauth

Jpproject.identityserver4.adminui
🔧 ASP.NET Core 3 & Angular 8 Administration Panel for 💞IdentityServer4 and ASP.NET Core Identity
Stars: ✭ 717 (+502.52%)
Mutual labels:  identityserver4
Blazor Wasm Identity Grpc
Blazor WASM, IdentityServer4, Kestrel Web Server, Entity Framework Code First SQLite Database with Multiple Roles, Additional User Claims & gRPC with Roles Authorization.
Stars: ✭ 61 (-48.74%)
Mutual labels:  identityserver4
Crm
A lightweight CRM application builds with microservices architecture
Stars: ✭ 102 (-14.29%)
Mutual labels:  identityserver4
Identityserver4.samples
Samples for IdentityServer4
Stars: ✭ 1,002 (+742.02%)
Mutual labels:  identityserver4
Identityserver4.openadmin
Open Source Admin UI for IdentityServer4
Stars: ✭ 54 (-54.62%)
Mutual labels:  identityserver4
Aspnetcorespa
Asp.Net 5.0 & Angular 11 SPA Fullstack application with plenty of examples. Live demo:
Stars: ✭ 1,211 (+917.65%)
Mutual labels:  identityserver4
Identityserver4.samples
Samples for IdentityServer4,use .net core 2.0
Stars: ✭ 561 (+371.43%)
Mutual labels:  identityserver4
Identitybase
IdentityBase is a Universal Identity Platform for web, mobile and IoT built on top of IdentityServer.
Stars: ✭ 112 (-5.88%)
Mutual labels:  identityserver4
Identityserver4 Swagger Integration
How to get Swashbuckle or NSwag Swagger UI's working with IdentityServer 4
Stars: ✭ 60 (-49.58%)
Mutual labels:  identityserver4
Vuejsoidcclient
project vueJs with oidc-client library
Stars: ✭ 88 (-26.05%)
Mutual labels:  identityserver4
Identityserver4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
Stars: ✭ 8,428 (+6982.35%)
Mutual labels:  identityserver4
Aspnetcoreidentityserver4resourceownerpassword
ASP.NET Core IdentityServer4 Resource Owner Flow Refresh token and custom user repository
Stars: ✭ 44 (-63.03%)
Mutual labels:  identityserver4
Aspnetcorewindowsauth
Local and Windows Authentication, ASP.NET Core MVC, IdentityServer4
Stars: ✭ 87 (-26.89%)
Mutual labels:  identityserver4
Abp.zerocore.identityserver4.configuration
IdentityServer4 ConfigurationStore(ClientStore,ResourceStore,CorsPolicyService) for Abp(https://github.com/aspnetboilerplate/aspnetboilerplate)
Stars: ✭ 25 (-78.99%)
Mutual labels:  identityserver4
Identityserver4 Course
本教程由 NCC 成员 晓晨Master 编写。
Stars: ✭ 108 (-9.24%)
Mutual labels:  identityserver4
Aspnet5identityserverangularimplicitflow
OpenID Connect Code / Implicit Flow with Angular and ASP.NET Core 5 IdentityServer4
Stars: ✭ 670 (+463.03%)
Mutual labels:  identityserver4
Aspnetcoreid4external
external OpenID Connect Login to IdentityServer4 with AAD
Stars: ✭ 63 (-47.06%)
Mutual labels:  identityserver4
Samples.aspnetcore Identityserver4
IdentityServer4 sample with .NET Core and ASP.NET Core 2.0
Stars: ✭ 115 (-3.36%)
Mutual labels:  identityserver4
Identityserver4.contrib.redisstore
A persistence layer using Redis DB for operational data and for caching capability for Identity Server 4
Stars: ✭ 108 (-9.24%)
Mutual labels:  identityserver4
Greatwall
Util应用框架配套的权限管理系统
Stars: ✭ 88 (-26.05%)
Mutual labels:  identityserver4

Project Available as Nuget Package , click here

Exchanging external Tokens (Google, Twitter, Facebook,LinkedIn) with IdentityServer access tokens using an extension grant

Supported providers

  • [x] Facebook
  • [x] LinkedIn
  • [x] Twitter
  • [x] Google
  • [ ] GitHub

How to exchange external tokens for IdentityServer access token ?

  • Request authentication using the provider's native library.
  • Exchange external token with IdentityServer token by making following request to IdentityServer.
POST connect/token
     
     client_id = [your_client_id]
     client_secret = [your_client_secret]
     scopes = [your_scopes]
     grant_type = external
     provider = facebook 
     external_token  = [facebook_access_token]
  • If user is already registered then IdentityServer will return the access token, otherwise it will send the user's data and prompt for an email parameter to be added, in this case make another request with an extra email parameter.
POST connect/token
    
    client_id = [your_client_id]
    client_secret = [your_client_secret]
    scopes = [your_scopes]
    grant_type = external
    provider = facebook 
    email = [email protected]
    external_token  = [facebook_access_token]

You can change provider to Facebook , Google , Twitter and LinkedIn and provide respective token in the external_token parameter.

How to setup an external provider

  1. Derive an interface from IExternalAuthProvider
public interface IMyCustomProvider : IExternalAuthProvider {
    Provider provider {get;}
}
  1. Add your provider to ProviderType enum
public enum ProviderType {
  
  Facebook,
  Twitter,
  Google,
  MyCustomProvider
}
  1. Add provider info to ProviderDataSource
 public class ProviderDataSource
    {
        public static IEnumerable<Provider> GetProviders()
        {
            return new List<Provider>
            {
                new Provider
                {
                    ProviderId = 1,
                    Name = "Facebook",
                    UserInfoEndPoint = "https://graph.facebook.com/v2.8/me"
                },
                new Provider
                {
                    ProviderId = 2,
                    Name = "Google",
                    UserInfoEndPoint = "https://www.googleapis.com/oauth2/v2/userinfo"
                },
                 new Provider
                {
                    ProviderId = 3,
                    Name = "Twitter",
                    UserInfoEndPoint = "https://api.twitter.com/1.1/account/verify_credentials.json"
                },
                new Provider 
                {
                    ProviderId = 4,
                    Name="MyCustomProvider",
                    UserInfoEndPoint = "[url to end point which validates the token and returns user data]"
                }
            };
        }
    }

  1. Provide an implementation for IMyCustomProvider
public class MyCustomProvider : IMyCustomProvider {

private readonly HttpClient _httpClient;
public MyCustomProvider(HttpClient httpClient) {
  _httpClient = httpClient;
}

public Provider =>_providerRepository.Get()
                                    .FirstOrDefault(x => x.Name.ToLower() == ProviderType.MyCustomProvider.ToString().ToLower());
                                    
public JObject GetUserInfo(string accessToken) {

 var query = "[build your request according to your providers configuration]";
 
 var result = _httpClient.GetAsync(Provider.UserInfoEndPoint + query).Result;
            if (result.IsSuccessStatusCode)
            {
                var infoObject = JObject.Parse(result.Content.ReadAsStringAsync().Result);
                return infoObject;
            }
            return null;

}
}
  1. Bind IMyCustomProvider in ServiceCollectionExtensions
 public static IServiceCollection AddProviders(this IServiceCollection services)
        {
            services.AddTransient<IFacebookAuthProvider, FacebookAuthProvider>();
            services.AddTransient<ITwitterAuthProvider, TwitterAuthProvider>();
            services.AddTransient<IGoogleAuthProvider, GoogleAuthProvider>();
            services.AddTransient<IMyCustomProvider,MyCustomProvider>();
            return services;
        }
  1. Add MyCustomProvider to ExternalAuthenticationGrant
  providers = new Dictionary<ProviderType, IExternalAuthProvider>();
            providers.Add(ProviderType.Facebook, _facebookAuthProvider);
            providers.Add(ProviderType.Google, _googleAuthProvider);
            providers.Add(ProviderType.Twitter, _twitterAuthProvider);
            providers.Add(ProviderType.LinkedIn, _linkedAuthProvider);
            providers.Add(ProviderType.MyCustomProvider, _myCustomProvider);
  1. Make a request to IdentityServer using new provider
POST connect/token
     
     client_id = [your_client_id]
     client_secret = [your_client_secret]
     scopes = [your_scopes]
     grant_type = external
     provider = mycustomprovider 
     external_token  = [access_token_from_custom_provider]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].