public CiscoSparkAuthenticationOptions()
        {
            ClaimsIssuer = CiscoSparkAuthenticationDefaults.Issuer;
            CallbackPath = new PathString(CiscoSparkAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = CiscoSparkAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = CiscoSparkAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = CiscoSparkAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "displayName");
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.Value <JArray>("emails")?.First?.Value <string>());
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new <see cref="MicrosoftAccountOptions"/>.
        /// </summary>
        public MicrosoftAccountOptions()
        {
            CallbackPath            = new PathString("/signin-microsoft");
            AuthorizationEndpoint   = MicrosoftAccountDefaults.AuthorizationEndpoint;
            TokenEndpoint           = MicrosoftAccountDefaults.TokenEndpoint;
            UserInformationEndpoint = MicrosoftAccountDefaults.UserInformationEndpoint;
            Scope.Add("https://graph.microsoft.com/user.read");

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "displayName");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "givenName");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "surname");
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.GetString("mail") ?? user.GetString("userPrincipalName"));
        }
        public SalesforceAuthenticationOptions()
        {
            ClaimsIssuer = SalesforceAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(SalesforceAuthenticationDefaults.CallbackPath);

            Environment = SalesforceAuthenticationDefaults.Environment;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "user_id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "user_name");
            ClaimActions.MapJsonKey("urn:salesforce:email", "email");
            ClaimActions.MapJsonKey("urn:salesforce:thumbnail_photo", "thumbnail");
            ClaimActions.MapJsonKey("urn:salesforce:utc_offset", "utcOffset");
            ClaimActions.MapCustomJson("urn:salesforce:rest_url", user => user["urls"]?.Value <string>("rest"));
        }
Exemple #4
0
 public FrontierOptions()
 {
     CallbackPath            = new PathString("/signin-frontier");
     AuthorizationEndpoint   = FrontierDefaults.AuthorizationEndpoint;
     TokenEndpoint           = FrontierDefaults.TokenEndpoint;
     UserInformationEndpoint = FrontierDefaults.UserInformationEndpoint;
     Scope.Add("auth");
     Scope.Add("capi");
     ClaimActions.MapJsonKey("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "customer_id");
     ClaimActions.MapJsonKey("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "email");
     ClaimActions.MapCustomJson("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", GetUserName);
     ClaimActions.MapJsonKey("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", "firstname");
     ClaimActions.MapJsonKey("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", "lastname");
     ClaimActions.MapJsonKey("urn:frontier:platform", "platform");
 }
Exemple #5
0
        public YandexAuthenticationOptions()
        {
            ClaimsIssuer = YandexAuthenticationDefaults.Issuer;
            CallbackPath = new PathString(YandexAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = YandexAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = YandexAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = YandexAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "last_name");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "first_name");
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.Value <JArray>("emails")?.First?.Value <string>());
        }
        public SalesforceAuthenticationOptions()
        {
            ClaimsIssuer = SalesforceAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(SalesforceAuthenticationDefaults.CallbackPath);

            Environment = SalesforceAuthenticationDefaults.Environment;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "user_id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "user_name");
            ClaimActions.MapJsonKey(Claims.Email, "email");
            ClaimActions.MapJsonKey(Claims.ThumbnailPhoto, "thumbnail");
            ClaimActions.MapJsonKey(Claims.UtcOffset, "utcOffset");
            ClaimActions.MapCustomJson(Claims.RestUrl, user => user["urls"]?.Value <string>("rest"));
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new <see cref="WeChatOptions"/>.
        /// </summary>
        public WeChatOptions()
        {
            CallbackPath            = new PathString("/signin-wechat");
            TokenEndpoint           = WeChatDefaults.TokenEndpoint;
            UserInformationEndpoint = WeChatDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "openid");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "nickname");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "sex", ClaimValueTypes.Integer);
            ClaimActions.MapJsonKey(ClaimTypes.Country, "country");
            ClaimActions.MapJsonKey(ClaimTypes.Uri, "headimgurl");
            ClaimActions.MapJsonKey("urn:wechat:province", "province");
            ClaimActions.MapJsonKey("urn:wechat:city", "city");
            ClaimActions.MapJsonKey("urn:wechat:unionid", "unionid");
            ClaimActions.MapCustomJson("urn:wechat:privilege", user => string.Join(",", user.SelectToken("privilege")?.Select(s => (string)s).ToArray() ?? new string[0]));
        }
Exemple #8
0
        public FreeeAuthenticationOptions()
        {
            ClaimsIssuer = FreeeAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(FreeeAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = FreeeAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = FreeeAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = FreeeAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "first_name");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "last_name");
            ClaimActions.MapCustomJson(ClaimTypes.Name, x => (string)x["display_name"] ?? $"{x["last_name"]} {x["first_name"]}");
        }
Exemple #9
0
        public FoursquareAuthenticationOptions()
        {
            ClaimsIssuer = FoursquareAuthenticationDefaults.Issuer;
            CallbackPath = new PathString(FoursquareAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = FoursquareAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = FoursquareAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = FoursquareAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "lastName");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "firstName");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "gender");
            ClaimActions.MapJsonKey(ClaimTypes.Uri, "canonicalUrl");
            ClaimActions.MapCustomJson(ClaimTypes.Name, user => $"{user.Value<string>("firstName")} {user.Value<string>("lastName")}");
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.Value <JObject>("contact")?.Value <string>("email"));
        }
Exemple #10
0
    public FoursquareAuthenticationOptions()
    {
        ClaimsIssuer = FoursquareAuthenticationDefaults.Issuer;
        CallbackPath = FoursquareAuthenticationDefaults.CallbackPath;

        AuthorizationEndpoint   = FoursquareAuthenticationDefaults.AuthorizationEndpoint;
        TokenEndpoint           = FoursquareAuthenticationDefaults.TokenEndpoint;
        UserInformationEndpoint = FoursquareAuthenticationDefaults.UserInformationEndpoint;

        ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
        ClaimActions.MapJsonKey(ClaimTypes.Surname, "lastName");
        ClaimActions.MapJsonKey(ClaimTypes.GivenName, "firstName");
        ClaimActions.MapJsonKey(ClaimTypes.Gender, "gender");
        ClaimActions.MapJsonKey(ClaimTypes.Uri, "canonicalUrl");
        ClaimActions.MapJsonSubKey(ClaimTypes.Email, "contact", "email");
        ClaimActions.MapCustomJson(ClaimTypes.Name, user => $"{user.GetString("firstName")} {user.GetString("lastName")}".Trim());
    }
Exemple #11
0
        /// <summary>
        /// Initializes a new <see cref="GoogleOptions"/>.
        /// </summary>
        public GoogleOptions()
        {
            CallbackPath            = new PathString("/signin-google");
            AuthorizationEndpoint   = GoogleDefaults.AuthorizationEndpoint;
            TokenEndpoint           = GoogleDefaults.TokenEndpoint;
            UserInformationEndpoint = GoogleDefaults.UserInformationEndpoint;
            Scope.Add("openid");
            Scope.Add("profile");
            Scope.Add("email");

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "displayName");
            ClaimActions.MapJsonSubKey(ClaimTypes.GivenName, "name", "givenName");
            ClaimActions.MapJsonSubKey(ClaimTypes.Surname, "name", "familyName");
            ClaimActions.MapJsonKey("urn:google:profile", "url");
            ClaimActions.MapCustomJson(ClaimTypes.Email, GoogleHelper.GetEmail);
        }
        public StackExchangeAuthenticationOptions()
        {
            ClaimsIssuer = StackExchangeAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(StackExchangeAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = StackExchangeAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = StackExchangeAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = StackExchangeAuthenticationDefaults.UserInformationEndpoint;
            BackchannelHttpHandler  = new HttpClientHandler {
                AutomaticDecompression = DecompressionMethods.GZip
            };

            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user => user[0]?.Value <string>("account_id"));
            ClaimActions.MapCustomJson(ClaimTypes.Name, user => user[0]?.Value <string>("display_name"));
            ClaimActions.MapCustomJson(ClaimTypes.Webpage, user => user[0]?.Value <string>("website_url"));
            ClaimActions.MapCustomJson("urn:stackexchange:link", user => user[0]?.Value <string>("link"));
        }
Exemple #13
0
        public PatreonAuthenticationOptions()
        {
            ClaimsIssuer = PatreonAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(PatreonAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = PatreonAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = PatreonAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = PatreonAuthenticationDefaults.UserInformationEndpoint;

            Scope.Add("users");
            Scope.Add("pledges-to-me");
            Scope.Add("my-campaign");

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapCustomJson(ClaimTypes.Name, user => user["attributes"]?.Value <string>("full_name"));
            ClaimActions.MapCustomJson(ClaimTypes.Webpage, user => user["attributes"]?.Value <string>("url"));
            ClaimActions.MapCustomJson("urn:patreon:avatar", user => user["attributes"]?.Value <string>("thumb_url"));
        }
Exemple #14
0
        public AWSCognitoOptions()
        {
            Scope.Add(AWSCognitoScopes.AwsCognitoSigninUserAdmin);

            // AWS Cognito claims
            // http://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html
            ClaimActions.MapJsonKey(ClaimTypes.StreetAddress, "address");
            ClaimActions.MapJsonKey(ClaimTypes.DateOfBirth, "birthdate");
            ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "gender");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
            ClaimActions.MapJsonKey(ClaimTypes.Locality, "locale");
            ClaimActions.MapJsonKey("MiddleName", "middle_name");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
            ClaimActions.MapJsonKey("Nickname", "nickname");
            ClaimActions.MapJsonKey(ClaimTypes.HomePhone, "phone_number");
            ClaimActions.MapJsonKey("Picture", "picture");
            ClaimActions.MapJsonKey("PreferredName", "preferred_username");
            ClaimActions.MapJsonKey("Profile", "profile");
            ClaimActions.MapJsonKey("Timezone", "timezone");
            ClaimActions.MapJsonKey("Timezone", "timezone");
            ClaimActions.MapJsonKey("UpdatedAt", "updated_at");
            ClaimActions.MapJsonKey(ClaimTypes.Webpage, "website");

            // UserId
            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, (json) =>
            {
                JToken token;
                if (json.TryGetValue("identities", out token))
                {
                    JArray identities = JArray.Parse(token.ToString());
                    foreach (JToken identity in identities)
                    {
                        if (JObject.Parse(identity.ToString()).TryGetValue("userId", out token))
                        {
                            return(token.Value <string>());
                        }
                    }
                }
                return(null);
            });
        }
Exemple #15
0
        public PaypalAuthenticationOptions()
        {
            ClaimsIssuer = PaypalAuthenticationDefaults.Issuer;
            CallbackPath = PaypalAuthenticationDefaults.CallbackPath;

            AuthorizationEndpoint   = PaypalAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = PaypalAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = PaypalAuthenticationDefaults.UserInformationEndpoint;

            Scope.Add("openid");
            Scope.Add("profile");
            Scope.Add("email");

            ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
            ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
            ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user => user.Value <string>("user_id")?.Split('/')?.LastOrDefault());
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.Value <JArray>("emails")?.FirstOrDefault(email => email.Value <bool>("primary"))?.Value <string>("value"));
        }
Exemple #16
0
        public ZaloAuthenticationOptions()
        {
            ClaimsIssuer = ZaloAuthenticationDefaults.Issuer;
            CallbackPath = ZaloAuthenticationDefaults.CallbackPath;

            AuthorizationEndpoint   = ZaloAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = ZaloAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = ZaloAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "gender");
            ClaimActions.MapCustomJson(ClaimTypes.DateOfBirth, user =>
            {
                return(DateTime.TryParseExact(user.GetString("birthday"), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateOfBirth)
                    ? dateOfBirth.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
                    : string.Empty);
            });
        }
Exemple #17
0
        public SpotifyAuthenticationOptions()
        {
            ClaimsIssuer = SpotifyAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(SpotifyAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = SpotifyAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = SpotifyAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = SpotifyAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "display_name");
            ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            ClaimActions.MapJsonKey(ClaimTypes.DateOfBirth, "birthdate");
            ClaimActions.MapJsonKey(ClaimTypes.Country, "country");
            ClaimActions.MapJsonKey(ClaimTypes.Uri, "uri");
            ClaimActions.MapJsonKey(Claims.Product, "product");
            ClaimActions.MapJsonSubKey(Claims.Url, "external_urls", "spotify");
            ClaimActions.MapCustomJson(Claims.ProfilePicture, user => user.Value <JArray>("images")?.First?.Value <string>("url"));
        }
Exemple #18
0
        public SlackAuthenticationOptions()
        {
            ClaimsIssuer = SlackAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(SlackAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = SlackAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = SlackAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = SlackAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user =>
                                       string.Concat(user["team"]["id"], "|", user["user"]["id"]));
            ClaimActions.MapJsonSubKey(ClaimTypes.Name, "user", "name");
            ClaimActions.MapJsonSubKey(ClaimTypes.Email, "user", "email");
            ClaimActions.MapJsonSubKey("urn:slack:user_id", "user", "id");
            ClaimActions.MapJsonSubKey("urn:slack:team_id", "team", "id");
            ClaimActions.MapJsonSubKey("urn:slack:team_name", "team", "name");

            Scope.Add("identity.basic");
        }
        public SlackAuthenticationOptions()
        {
            ClaimsIssuer = SlackAuthenticationDefaults.Issuer;

            CallbackPath = SlackAuthenticationDefaults.CallbackPath;

            AuthorizationEndpoint   = SlackAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = SlackAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = SlackAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user =>
                                       string.Concat(user.GetProperty("team").GetString("id"), "|", user.GetProperty("user").GetString("id")));
            ClaimActions.MapJsonSubKey(ClaimTypes.Name, "user", "name");
            ClaimActions.MapJsonSubKey(ClaimTypes.Email, "user", "email");
            ClaimActions.MapJsonSubKey(Claims.UserId, "user", "id");
            ClaimActions.MapJsonSubKey(Claims.TeamId, "team", "id");
            ClaimActions.MapJsonSubKey(Claims.TeamName, "team", "name");

            Scope.Add("identity.basic");
        }
        public BaiduAuthenticationOptions()
        {
            ClaimsIssuer = BaiduAuthenticationDefaults.Issuer;
            CallbackPath = new PathString(BaiduAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = BaiduAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = BaiduAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = BaiduAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "uid");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "uname");
            ClaimActions.MapCustomJson(BaiduAuthenticationConstants.Claims.Portrait,
                                       user =>
            {
                var portrait = user.Value <string>("portrait");
                return(string.IsNullOrWhiteSpace(portrait)
                        ? null
                        : $"https://tb.himg.baidu.com/sys/portrait/item/{WebUtility.UrlEncode(portrait)}");
            });
        }
        /// <summary>
        /// Initializes a new <see cref="SpaceOptions"/>.
        /// </summary>
        public SpaceOptions()
        {
            CallbackPath = new PathString("/signin-space");

            AuthorizationEndpoint   = SpaceDefaults.AuthorizationEndpointPath;
            TokenEndpoint           = SpaceDefaults.TokenEndpointPath;
            UserInformationEndpoint = SpaceDefaults.UserInformationEndpointPath;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(SpaceClaimTypes.UserId, "id");
            ClaimActions.MapJsonKey(SpaceClaimTypes.UserName, "username");
            ClaimActions.MapCustomJson(SpaceClaimTypes.SmallAvatar, element => element.TryGetProperty("smallAvatar", out var p) && ServerUrl != null ? ServerUrl.ToString().TrimEnd('/') + "/d/" + p.GetString() : null);
            ClaimActions.MapCustomJson(SpaceClaimTypes.ProfilePicture, element => element.TryGetProperty("profilePicture", out var p) && ServerUrl != null ? ServerUrl.ToString().TrimEnd('/') + "/d/" + p.GetString() : null);
            ClaimActions.MapJsonSubKey(SpaceClaimTypes.FirstName, "name", "firstName");
            ClaimActions.MapJsonSubKey(SpaceClaimTypes.LastName, "name", "lastName");
            ClaimActions.MapCustomJson(ClaimTypes.Name, element =>
            {
                if (element.TryGetProperty("name", out var nameElement) && nameElement.ValueKind == JsonValueKind.Object)
                {
                    return(nameElement.TryGetProperty("firstName", out var firstName) &&
                           nameElement.TryGetProperty("lastName", out var lastName)
                        ? $"{firstName} {lastName}"
                        : null);
                }

                return(null);
            });
            ClaimActions.MapCustomJson(ClaimTypes.Email, element =>
            {
                if (element.TryGetProperty("emails", out var emailElements) && emailElements.ValueKind == JsonValueKind.Array)
                {
                    var emailElement = emailElements.EnumerateArray().FirstOrDefault();
                    if (emailElement.TryGetProperty("email", out var email))
                    {
                        return(email.GetString());
                    }
                }

                return(null);
            });
        }
        public WeChatOptions()
        {
            CallbackPath            = new PathString("/signin-wechat");
            AuthorizationEndpoint   = WeChatDefaults.AuthorizationEndpoint;
            AuthorizationEndpoint2  = WeChatDefaults.AuthorizationEndpoint2;
            TokenEndpoint           = WeChatDefaults.TokenEndpoint;
            UserInformationEndpoint = WeChatDefaults.UserInformationEndpoint;

            //Scope 表示应用授权作用域。
            //网页上登录(非微信浏览器)需要两个Scope,一个是UserInfo,一个是Login
            Scope.Add(UserInfoScope);
            Scope.Add(LoginScope);

            //微信内嵌浏览器Login只需要UserInfo
            Scope2 = new List <string>();
            Scope2.Add(UserInfoScope);

            //除了openid外,其余的都可能为空,因为微信获取用户信息是有单独权限的
            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "openid");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "nickname");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "sex", ClaimValueTypes.Integer);
            ClaimActions.MapJsonKey(ClaimTypes.Country, "country");     //ClaimTypes.Locality
            ClaimActions.MapJsonKey("urn:wechat:province", "province"); //ClaimTypes.StateOrProvince
            ClaimActions.MapJsonKey("urn:wechat:city", "city");         //ClaimTypes.StreetAddress
            ClaimActions.MapJsonKey(ClaimTypes.Uri, "headimgurl");
            ClaimActions.MapCustomJson("urn:wechat:privilege", user =>
            {
                var privilege = new List <string>();
                if (user.TryGetProperty("privilege", out var property))
                {
                    privilege = property.EnumerateArray().Select(x => x.GetString()).ToList();
                }

                return(string.Join(",", privilege));
            });
            // ClaimActions.MapCustomJson("urn:wechat:privilege", user =>  string.Join(",",user.GetProperty("privilege")?.EnumerateArray()?.Select(s => s.ToString()).ToArray() ?? new string[0]));
            ClaimActions.MapJsonKey("urn:wechat:unionid", "unionid");


            IsWeChatBrowser = (r) => r.Headers[HeaderNames.UserAgent].ToString().ToLower().Contains("micromessenger");
        }
Exemple #23
0
        public WeChatOptions()
        {
            CallbackPath = new PathString("/signin-wechat");

            TokenEndpoint           = WeChatDefaults.TokenEndpoint;
            UserInformationEndpoint = WeChatDefaults.UserInformationEndpoint;


            //除了openid外,其余的都可能为空,因为微信获取用户信息是有单独权限的
            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "openid");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "nickname");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "sex", ClaimValueTypes.Integer);
            ClaimActions.MapJsonKey(ClaimTypes.Country, "country");     //ClaimTypes.Locality
            ClaimActions.MapJsonKey("urn:wechat:province", "province"); //ClaimTypes.StateOrProvince
            ClaimActions.MapJsonKey("urn:wechat:city", "city");         //ClaimTypes.StreetAddress
            ClaimActions.MapJsonKey(ClaimTypes.Uri, "headimgurl");
            ClaimActions.MapCustomJson("urn:wechat:privilege", user => string.Join(",", user.SelectToken("privilege")?.Select(s => (string)s).ToArray() ?? new string[0]));
            ClaimActions.MapJsonKey("urn:wechat:unionid", "unionid");

            IsWeChatBrowser = (r) => r.IsWeChatBroswer();
        }
        public TwitchAuthenticationOptions()
        {
            ClaimsIssuer = TwitchAuthenticationDefaults.Issuer;
            CallbackPath = TwitchAuthenticationDefaults.CallbackPath;

            AuthorizationEndpoint   = TwitchAuthenticationDefaults.AuthorizationEndPoint;
            TokenEndpoint           = TwitchAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = TwitchAuthenticationDefaults.UserInformationEndpoint;

            Scope.Add("user:read:email");

            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user => GetData(user, "id"));
            ClaimActions.MapCustomJson(ClaimTypes.Name, user => GetData(user, "login"));
            ClaimActions.MapCustomJson(Claims.DisplayName, user => GetData(user, "display_name"));
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => GetData(user, "email"));
            ClaimActions.MapCustomJson(Claims.Type, user => GetData(user, "type"));
            ClaimActions.MapCustomJson(Claims.BroadcasterType, user => GetData(user, "broadcaster_type"));
            ClaimActions.MapCustomJson(Claims.Description, user => GetData(user, "description"));
            ClaimActions.MapCustomJson(Claims.ProfileImageUrl, user => GetData(user, "profile_image_url"));
            ClaimActions.MapCustomJson(Claims.OfflineImageUrl, user => GetData(user, "offline_image_url"));
        }
        public TwitchAuthenticationOptions()
        {
            ClaimsIssuer = "Twitch";
            CallbackPath = "/auth/twitch/callback";

            AuthorizationEndpoint   = "https://id.twitch.tv/oauth2/authorize";
            TokenEndpoint           = "https://id.twitch.tv/oauth2/token";
            UserInformationEndpoint = "https://api.twitch.tv/helix/users/";

            Scope.Add("user:read:email");

            ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user => GetData(user, "id"));
            ClaimActions.MapCustomJson(ClaimTypes.Name, user => GetData(user, "login"));
            ClaimActions.MapCustomJson(ClaimTypes.Email, user => GetData(user, "email"));

            ClaimActions.MapCustomJson("urn:twitch:displayname", user => GetData(user, "display_name"));
            ClaimActions.MapCustomJson("urn:twitch:type", user => GetData(user, "type"));
            ClaimActions.MapCustomJson("urn:twitch:broadcastertype", user => GetData(user, "broadcaster_type"));
            ClaimActions.MapCustomJson("urn:twitch:description", user => GetData(user, "description"));
            ClaimActions.MapCustomJson("urn:twitch:profileimageurl", user => GetData(user, "profile_image_url"));
            ClaimActions.MapCustomJson("urn:twitch:offlineimageurl", user => GetData(user, "offline_image_url"));
        }
        public HarvestAuthenticationOptions()
        {
            ClaimsIssuer = HarvestAuthenticationDefaults.Issuer;

            CallbackPath = new PathString(HarvestAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = HarvestAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = HarvestAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = HarvestAuthenticationDefaults.UserInformationEndpoint;


            ClaimActions.MapJsonSubKey(ClaimTypes.NameIdentifier, "user", "id");
            ClaimActions.MapCustomJson(ClaimTypes.Name, payload =>
            {
                var user  = payload.Value <JObject>("user");
                var parts = new[] { user.Value <string>("first_name"), user.Value <string>("last_name") };
                return(string.Join(" ", parts.Where(x => !string.IsNullOrEmpty(x))));
            });
            ClaimActions.MapJsonSubKey(ClaimTypes.GivenName, "user", "first_name");
            ClaimActions.MapJsonSubKey(ClaimTypes.Surname, "user", "last_name");
            ClaimActions.MapJsonSubKey(ClaimTypes.Email, "user", "email");
        }
Exemple #27
0
        public WeChatPublicAuthenticationOptions()
        {
            ClaimsIssuer = WeChatPublicAuthenticationDefaults.Issuer;
            CallbackPath = new PathString(WeChatPublicAuthenticationDefaults.CallbackPath);

            AuthorizationEndpoint   = WeChatPublicAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = WeChatPublicAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = WeChatPublicAuthenticationDefaults.UserInformationEndpoint;
            IsRelation = WeChatPublicAuthenticationDefaults.IsRelation;
            //Scope.Add("snsapi_login");
            Scope.Add("snsapi_userinfo");
            //如果在微信开放平台做了关联,则取Unionid,反之取Openid
            if (IsRelation)
            {
                ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "unionid");
            }
            else
            {
                ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "openid");
            }

            ClaimActions.MapJsonKey(ClaimTypes.Name, "nickname");
            ClaimActions.MapJsonKey(ClaimTypes.Gender, "sex", ClaimValueTypes.Integer);
            ClaimActions.MapJsonKey(Claims.Unionid, "unionid");
            ClaimActions.MapJsonKey(Claims.OpenId, "openid");
            ClaimActions.MapJsonKey(Claims.NickName, "nickname");
            ClaimActions.MapJsonKey(Claims.Language, "language");
            ClaimActions.MapJsonKey(Claims.City, "city");
            ClaimActions.MapJsonKey(Claims.Province, "province");
            ClaimActions.MapJsonKey(ClaimTypes.Country, "country");
            ClaimActions.MapJsonKey(Claims.HeadImgUrl, "headimgurl");
            ClaimActions.MapCustomJson(Claims.Privilege, user =>
            {
                var value = user.Value <JArray>("privilege");
                return(value == null ? null : string.Join(",", value.ToObject <string[]>()));
            });
            //ClaimActions.MapCustomJson(Claims.Privilege, user => string.Join(",", user.SelectToken("privilege")?.Select(s => (string)s).ToArray() ?? new string[0]));
        }
        public DiscordAuthenticationOptions()
        {
            ClaimsIssuer            = DiscordAuthenticationDefaults.Issuer;
            CallbackPath            = DiscordAuthenticationDefaults.CallbackPath;
            AuthorizationEndpoint   = DiscordAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint           = DiscordAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = DiscordAuthenticationDefaults.UserInformationEndpoint;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "username");
            ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            ClaimActions.MapJsonKey(Claims.AvatarHash, "avatar");
            ClaimActions.MapJsonKey(Claims.Discriminator, "discriminator");
            ClaimActions.MapCustomJson(Claims.AvatarUrl, user =>
                                       string.Format(
                                           CultureInfo.InvariantCulture,
                                           DiscordAvatarFormat,
                                           DiscordCdn.TrimEnd('/'),
                                           user.GetString("id"),
                                           user.GetString("avatar")));

            Scope.Add("identify");
        }
        public WeChatOptions()
        {
            CallbackPath          = new PathString("/signin-wechat");
            AuthorizationEndpoint = WeChatDefaults.AuthorizationEndpoint;
            AuthorizationInWeiXinBrowerEndpoint = WeChatDefaults.AuthorizationInWeiXinBrowerEndpoint;
            TokenEndpoint           = WeChatDefaults.TokenEndpoint;
            UserInformationEndpoint = WeChatDefaults.UserInformationEndpoint;

            //Scope 表示应用授权作用域。
            //网页上登录(非微信浏览器)需要两个Scope,一个是UserInfo,一个是Login
            Scope.Add(UserInfoScope);
            Scope.Add(LoginScope);

            //微信内嵌浏览器Login只需要UserInfo
            Scope2 = new List <string>();
            Scope2.Add(UserInfoScope);

            //除了openid外,其余的都可能为空,因为微信获取用户信息是有单独权限的
            ClaimActions.MapJsonKey("urn:wechat:openid", "openid");
            ClaimActions.MapJsonKey("urn:wechat:nickname", "nickname");
            ClaimActions.MapJsonKey("urn:wechat:sex", "sex", ClaimValueTypes.Integer);
            ClaimActions.MapJsonKey("urn:wechat:country", "country");   //ClaimTypes.Locality
            ClaimActions.MapJsonKey("urn:wechat:province", "province"); //ClaimTypes.StateOrProvince
            ClaimActions.MapJsonKey("urn:wechat:city", "city");         //ClaimTypes.StreetAddress
            ClaimActions.MapJsonKey("urn:wechat:headimgurl", "headimgurl");
            ClaimActions.MapJsonKey("urn:wechat:unionid", "unionid");
            ClaimActions.MapCustomJson("urn:wechat:privilege", user =>
            {
                if (!user.TryGetProperty("privilege", out var value) || value.ValueKind != System.Text.Json.JsonValueKind.Array)
                {
                    return(null);
                }
                return(string.Join(",", value.EnumerateArray().Select(element => element.GetString())));
            });

            IsWeChatBrowser = (r) => r.Headers[HeaderNames.UserAgent].ToString().ToLower().Contains("micromessenger");
        }
Exemple #30
0
    public LinkedInAuthenticationOptions()
    {
        ClaimsIssuer = LinkedInAuthenticationDefaults.Issuer;
        CallbackPath = LinkedInAuthenticationDefaults.CallbackPath;

        AuthorizationEndpoint   = LinkedInAuthenticationDefaults.AuthorizationEndpoint;
        TokenEndpoint           = LinkedInAuthenticationDefaults.TokenEndpoint;
        UserInformationEndpoint = LinkedInAuthenticationDefaults.UserInformationEndpoint;
        EmailAddressEndpoint    = LinkedInAuthenticationDefaults.EmailAddressEndpoint;

        Scope.Add("r_liteprofile");
        Scope.Add("r_emailaddress");

        ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, ProfileFields.Id);
        ClaimActions.MapCustomJson(ClaimTypes.Name, user => GetFullName(user));
        ClaimActions.MapCustomJson(ClaimTypes.GivenName, user => GetMultiLocaleString(user, ProfileFields.FirstName));
        ClaimActions.MapCustomJson(ClaimTypes.Surname, user => GetMultiLocaleString(user, ProfileFields.LastName));
        ClaimActions.MapCustomJson(Claims.PictureUrl, user => GetPictureUrls(user)?.LastOrDefault());
        ClaimActions.MapCustomJson(Claims.PictureUrls, user =>
        {
            var urls = GetPictureUrls(user);
            return(urls == null ? null : string.Join(',', urls));
        });
    }