當前位置: 首頁>>代碼示例>>C#>>正文


C# OAuth.OAuthValidateClientAuthenticationContext類代碼示例

本文整理匯總了C#中Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext的典型用法代碼示例。如果您正苦於以下問題:C# OAuthValidateClientAuthenticationContext類的具體用法?C# OAuthValidateClientAuthenticationContext怎麽用?C# OAuthValidateClientAuthenticationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OAuthValidateClientAuthenticationContext類屬於Microsoft.Owin.Security.OAuth命名空間,在下文中一共展示了OAuthValidateClientAuthenticationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId;
            string clientSecret;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null)
            {
                context.SetError("invalid_clientId", "client_Id is not set");
                return Task.FromResult<object>(null);
            }

            var resource = ResourceStore.FindResource(context.ClientId);

            if (resource == null)
            {
                context.SetError("invalid_clientId", string.Format("Invalid client_id '{0}'", context.ClientId));
                return Task.FromResult<object>(null);
            }

            context.Validated();
            return Task.FromResult<object>(null);
        }
開發者ID:mnasif786,項目名稱:PortalAPIs,代碼行數:27,代碼來源:ApplicationOAuthProvidercs.cs

示例2: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId = string.Empty;
            string clientSecret = string.Empty;
            Client client = null;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null)
            {
                //Remove the comments from the below line context.SetError, and invalidate context 
                //if you want to force sending clientId/secrects once obtain access tokens. 
                context.Validated();
                //context.SetError("invalid_clientId", "ClientId should be sent.");
                return Task.FromResult<object>(null);
            }

            using (AuthRepository _repo = new AuthRepository())
            {
                client = _repo.FindClient(context.ClientId);
            }

            if (client == null)
            {
                context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", context.ClientId));
                return Task.FromResult<object>(null);
            }

            if (client.ApplicationType == ApplicationTypes.NativeConfidential)
            {
                if (string.IsNullOrWhiteSpace(clientSecret))
                {
                    context.SetError("invalid_clientId", "Client secret should be sent.");
                    return Task.FromResult<object>(null);
                }
                else
                {
                    if (client.Secret != HashHelper.GetHash(clientSecret))
                    {
                        context.SetError("invalid_clientId", "Client secret is invalid.");
                        return Task.FromResult<object>(null);
                    }
                }
            }

            if (!client.Active)
            {
                context.SetError("invalid_clientId", "Client is inactive.");
                return Task.FromResult<object>(null);
            }

            context.OwinContext.Set<string>("as:clientAllowedOrigin", client.AllowedOrigin);
            context.OwinContext.Set<string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());

            context.Validated();
            return Task.FromResult<object>(null);
        }
開發者ID:FarajiA,項目名稱:AspNetIdentity.WebApi,代碼行數:60,代碼來源:CustomOAuthProvider.cs

示例3: ValidateClientAuthentication

        /// <summary>
        /// Validates the client id
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {

            string clientId;
            string clientSecret;
            // Gets the clientid and client secret from authenticate header
            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                // try to get form values
                context.TryGetFormCredentials(out clientId, out clientSecret);

            }

            // Validate clientid and clientsecret. You can omit validating client secret if none is provided in your request (as in sample client request above)
            var validClient = true;//!string.IsNullOrWhiteSpace(clientId);

            if (validClient)
            {
                // Need to make the client_id available for later security checks
                context.OwinContext.Set<string>("as:client_id", clientId);

                context.Validated();
            }
            else
            {
                context.Rejected();
            }

            return Task.FromResult(0);

        }
開發者ID:KryptPad,項目名稱:KryptPadWebsite,代碼行數:36,代碼來源:AccessTokenProvider.cs

示例4: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            // Note: We only support resource owner password grants, in which case there is no client_id involved
            if (context.ClientId == null) context.Validated();

            return Task.FromResult<object>(null);
        }
開發者ID:BerndVertommen,項目名稱:EvaluationPlatform,代碼行數:7,代碼來源:CustomOAuthProvider.cs

示例5: ValidateClientAuthentication

        /// <summary>
        /// responsible for validating if the Resource server (audience) is already registered in our Authorization server by reading the client_id value from the request
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId;
            string clientSecret;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null && String.IsNullOrWhiteSpace(clientId))
            {
                context.SetError("invalid_clientId", "client_Id is not set");
            }
            else if (!context.HasError)
            {
                var audience = AudiencesStore.Instance.FindAudience(context.ClientId);
                if (audience == null)
                {
                  context.SetError("invalid_clientId", String.Format("Client '{0}' is not registered in the system.", context.ClientId));
                }
                else
                {
                    context.OwinContext.Set("as:clientId", clientId);
                    context.OwinContext.Set("as:clientAllowedOrigin", audience.AllowedOrigin);
                    context.Validated();
                }
            }
            return Task.FromResult<object>(null);
        }
開發者ID:Fanuer,項目名稱:EventCorp,代碼行數:35,代碼來源:CustomOAuthProvider.cs

示例6: ValidateClientAuthentication

		public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
		{
			context.Validated();

			await Task.FromResult<object>(null);

		}
開發者ID:JuninhoRoseira,項目名稱:br.com.klinderrh.social,代碼行數:7,代碼來源:AuthorizationServerProvider.cs

示例7: ValidateClientAuthentication

        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) {
            var clientId = context.Parameters["client_id"];
            if (!string.IsNullOrWhiteSpace(clientId)) {
                var grantType = context.Parameters["grant_type"];
                var clientSecret = context.Parameters["client_secret"];

                switch (grantType) {
                    case GrantType.Password:
                    case GrantType.ClientCredentials:
                        {
                            /* web application */
                            if (clientSecret == Application.WebApplication.ConsumerSecret) {
                                context.Validated(clientId);
                                return;
                            }

                            /*  mobile application */
                            if (clientSecret == Application.MobileApplication.ConsumerSecret) {
                                context.Validated(clientId);
                                return;
                            }
                        }
                        break;
                    case GrantType.RefreshToken:
                    default:
                        context.Validated(clientId);
                        return;
                }
            }

            context.Rejected();
        }
開發者ID:cemkurtulus,項目名稱:ck-oauth,代碼行數:32,代碼來源:AuthorizationServerProvider.cs

示例8: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            // validate client credentials
            // should be stored securely (salted, hashed, iterated)
            
            string id, secret;
            if (context.TryGetBasicCredentials(out id, out secret))
            {
                var client = _dbContext
                    .ApiClients
                    .AsEnumerable()
                    .SingleOrDefault(c => c.Id.ToString() == id && c.IsBlacklisted == false);

                if (client != null)
                {
                    // need to make the client_id available for later security checks
                    context.OwinContext.Set("as:client_id", client.Id.ToString());
                    //context.OwinContext.Set("as:client_name", client.Name);
                    context.Validated();
                    return Task.FromResult<object>(null);
                }

            }
            context.Rejected();
            return Task.FromResult<object>(null);
        }
開發者ID:rcrosbourne,項目名稱:MyQuestionnaire,代碼行數:26,代碼來源:SimpleAuthorizationServerProvider.cs

示例9: ValidateClientAuthentication

        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            // OAuth2 supports the notion of client authentication
            // this is not used here

            await TaskEx.Run(() => { context.Validated(); });
        }
開發者ID:XVincentX,項目名稱:SimInfo,代碼行數:7,代碼來源:AuthorizationServerProvider.cs

示例10: ValidateClientAuthentication

        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            try
            {
                string clientId, clientSecret;
                if (context.TryGetBasicCredentials(out clientId, out clientSecret) || context.TryGetFormCredentials(out clientId, out clientSecret))
                {
                    if (Validator.ValidateClient(clientId, clientSecret))
                    {
                        context.Validated();
                    }
                }
                else
                {
                    context.SetError("Invalid credentials");
                    context.Rejected();
                }
            }
            catch (Exception e)
            {
                context.SetError("Server error");
                context.Rejected();
            }

        }
開發者ID:rainymaple,項目名稱:PCG.GOAL,代碼行數:25,代碼來源:GoalOAuthProvider.cs

示例11: ValidateClientAuthentication

 /// <summary>
 /// 驗證Client Credentials[client_id與client_secret]
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     //http://localhost:48339/token
     //grant_type=client_credentials&client_id=irving&client_secret=123456&scope=user order
     /*
     grant_type     授與方式(固定為 “client_credentials”)
     client_id 	   分配的調用oauth的應用端ID
     client_secret  分配的調用oaut的應用端Secret
     scope 	       授權權限。以空格分隔的權限列表,若不傳遞此參數,代表請求用戶的默認權限
     */
     //validate client credentials should be stored securely (salted, hashed, iterated)
     string clientId;
     string clientSecret;
     //context.TryGetBasicCredentials(out clientId, out clientSecret);
     context.TryGetFormCredentials(out clientId, out clientSecret);
     //驗證用戶名密碼
     var clientValid = await _clientAuthorizationService.ValidateClientAuthorizationSecretAsync(clientId, clientSecret);
     if (!clientValid)
     {
         //Flurl 404 問題
         //context.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
         //context.Rejected();
         context.SetError(AbpConstants.InvalidClient, AbpConstants.InvalidClientErrorDescription);
         return;
     }
     //need to make the client_id available for later security checks
     context.OwinContext.Set<string>("as:client_id", clientId);
     context.Validated(clientId);
 }
開發者ID:WhitePoplar022,項目名稱:App.WebAPI,代碼行數:34,代碼來源:ClientAuthorizationServerProvider.cs

示例12: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId;
            string clientSecret;

            //first try to get the client details from the Authorization Basic header
            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                //no details in the Authorization Header so try to find matching post values
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret))
            {
                context.SetError("client_not_authorized", "invalid client details");
                return Task.FromResult<object>(null);
            }

            var dataLayer = new RepoManager(new DataLayerDapper()).DataLayer;
            var audienceDto = dataLayer.GetAudience(clientId);

            if (audienceDto == null || !clientSecret.Equals(audienceDto.Secret))
            {
                context.SetError("unauthorized_client", "unauthorized client");
                return Task.FromResult<object>(null);
            }

            context.Validated();
            return Task.FromResult<object>(null);
        }
開發者ID:statement1,項目名稱:OwinAuthorizationServers,代碼行數:30,代碼來源:CustomOAuthProvider.cs

示例13: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId = string.Empty;
            string clientSecret = string.Empty;
            string symmetricKeyAsBase64 = string.Empty;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null)
            {
                context.SetError("invalid_clientId", "client_Id is not set");
                return Task.FromResult<object>(null);
            }

            var audience = AudiencesStore.FindAudience(context.ClientId);

            if (audience == null)
            {
                context.SetError("invalid_clientId", string.Format("Invalid client_id '{0}'", context.ClientId));
                return Task.FromResult<object>(null);
            }

            context.Validated();
            return Task.FromResult<object>(null);
        }
開發者ID:AdaskoTheBeAsT,項目名稱:JWTAspNetWebApi,代碼行數:28,代碼來源:CustomOAuthProvider.cs

示例14: ValidateClientAuthentication

 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     await Task.Factory.StartNew(() =>
     {
         context.Validated();
     });
 }
開發者ID:jeffward01,項目名稱:ReviewApplicaiton,代碼行數:7,代碼來源:ReviewApplicationAuthorizationServiceProvider.cs

示例15: ValidateClientAuthentication

        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            //TODO Validate null property
            string id, secret;
            context.TryGetFormCredentials(out id, out secret);

            var type = context.Parameters.Get("type");
            switch (type)
            {
                case "admin":
                    if (id == null) id = context.Parameters.Get("Username") + "_SysAdmin";
                    context.Validated();
                    break;
                case "app":
                    if (secret != null) context.Validated();
                    break;
                default:
                    if (id != null) context.Validated();
                    type = string.Empty;
                    break;
            }

            context.OwinContext.Set<string>("as:client_id", id);
            context.OwinContext.Set<string>("as:client_secret", secret);
            context.OwinContext.Set<string>("as:type", type);
        }
開發者ID:hoangvv1409,項目名稱:codebase,代碼行數:26,代碼來源:AuthorizationServerProvider.cs


注:本文中的Microsoft.Owin.Security.OAuth.OAuthValidateClientAuthenticationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。