コード例 #1
0
        private dynamic AuthorizeByExternalProvider(ProviderAndAccessToken model, ExternalProvider externalProvider)
        {
            IKernel        kernel        = Infrastructure.DependencyResolver.GetKernel();
            IOauthProvider oauthProvider = kernel.Get <IOauthProvider>(externalProvider.ToString());

            try
            {
                dynamic userData = oauthProvider.Authorize(model);
                userData.userName = userData.userData.userName.Replace(" ", "");
                if (!userData.userName.ToString().Contains("@")) //google already adds @gmail.com to returned data so this should be optional.
                {
                    userData.userName = userData.userName + "@" + externalProvider.ToString() + ".com";
                }
                return(userData);
            }
            catch (Exception ex)
            {
                HttpContent contentPost = new StringContent("Facebook : " + ex.Message, Encoding.UTF8, "application/text");
                var         msg         = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = contentPost
                };
                throw new HttpResponseException(msg);
            }
        }
コード例 #2
0
ファイル: LocalAuth.cs プロジェクト: miahyap/ICT3x03-Team-10
 public LocalAuth(IOauthProvider oauthProvider, IDatabase database, IEmailSender emailSender,
                  IMemoryCache memoryCache, IConfiguration configuration, ILogger <LocalAuth> logger)
 {
     _oauthProvider = oauthProvider;
     _database      = database;
     _emailSender   = emailSender;
     _memoryCache   = memoryCache;
     _configuration = configuration;
     _logger        = logger;
     _weakPasswords = new HashSet <string>(File.ReadAllLines(configuration["AuthWordList:BadPassword"]));
     _badUsernames  = new HashSet <string>(File.ReadAllLines(configuration["AuthWordList:BadUsername"]));
 }