/// <summary>
        /// Describe your member here.
        /// </summary>
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            context.Validated();
        }
Exemplo n.º 2
0
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 3
0
 public override async System.Threading.Tasks.Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     //return base.ValidateClientAuthentication(context);
 }
        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 == Models.ApplicationTypes.NativeConfidential)
            {
                if (string.IsNullOrWhiteSpace(clientSecret))
                {
                    context.SetError("invalid_clientId", "Client secret should be sent.");
                    return(Task.FromResult <object>(null));
                }
                else
                {
                    if (client.Secret != Helper.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));

            //string clientId = string.Empty;
            //string clientSecret = string.Empty;

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

            //if (context.ClientId != null && context.ClientId != "1")
            //{
            //    using (PhoneDBContext db = new PhoneDBContext())
            //    {
            //        int CompanyID = int.Parse(clientId);
            //        string ApiKey = Helper.GetHash(clientSecret);
            //        if (db.Companies.Where(c => c.CompanyID == CompanyID && c.ApiKey == ApiKey).FirstOrDefault() != null)
            //            context.Validated();
            //    }
            //}
            //else
            //{
            //    context.Validated();
            //}
            //return Task.FromResult<object>(null);
        }
Exemplo n.º 5
0
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     return(base.ValidateClientAuthentication(context));
 }
Exemplo n.º 6
0
        //ati login
        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);
            //}
            //EPAGRIFFINEntities db = new EPAGRIFFINEntities();
            //client = db.Clients.FirstOrDefault(q => q.Id == context.ClientId);
            ////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 == (int)ApplicationTypes.NativeConfidential)
            //{
            //    if (string.IsNullOrWhiteSpace(clientSecret))
            //    {
            //        context.SetError("invalid_clientId", "Client secret should be sent.");
            //        return Task.FromResult<object>(null);
            //    }
            //    else
            //    {
            //        if (client.Secret != Helper.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));
        }
Exemplo n.º 7
0
        //Methods

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            return(Task.Factory.StartNew <bool>(context.Validated));
        }
        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 (Convert.ToInt32(client.ApplicationType) == (int)Models.ApplicationTypes.NativeConfidential)
            {
                if (string.IsNullOrWhiteSpace(clientSecret))
                {
                    context.SetError("invalid_clientId", "Client secret should be sent.");
                    return(Task.FromResult <object>(null));
                }
                else
                {
                    if (client.Secret != Helper.GetHash(clientSecret))
                    {
                        context.SetError("invalid_clientId", "Client secret is invalid.");
                        return(Task.FromResult <object>(null));
                    }
                }
            }

            if (!client.Active.Value)
            {
                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));

            //context.Validated();
        }
Exemplo n.º 9
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated(); // Valida o TOKEN no contexto que OAuth é responsavel - Valida TOKEN
 }
Exemplo n.º 10
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     //
     context.Validated();//any clientid Valid
 }
Exemplo n.º 11
0
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            context.Validated();

            return(Task.CompletedTask);
        }
 async public override System.Threading.Tasks.Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     try
     {
         context.Validated();
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 13
0
        /// <returns>Returns validation of client authentication</returns>
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            // Resource owner password credentials does not provide a client ID.

            context.Validated();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Called to validate that the origin of the request is a registered "client_id", and that the correct credentials for that client are
        /// present on the request. If the web application accepts Basic authentication credentials,
        /// context.TryGetBasicCredentials(out clientId, out clientSecret) may be called to acquire those values if present in the request header. If the web
        /// application accepts "client_id" and "client_secret" as form encoded POST parameters,
        /// context.TryGetFormCredentials(out clientId, out clientSecret) may be called to acquire those values if present in the request body.
        /// If context.Validated is not called the request will not proceed further.
        /// </summary>
        /// <param name="context">The context of the event carries information in and results out.</param>
        /// <returns>Task to enable asynchronous execution</returns>
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            this.options.Logger.Debug("Validating client id and secret");

            string clientId;
            string clientSecret;

            // Validate that redirect uri is specified
            // 'redirect_uri' must be specified for all calls that are not 'client_credentials' or 'refresh_token' grants.
            if (context.Parameters["redirect_uri"] == null && context.Parameters["grant_type"] != "client_credentials" && context.Parameters["grant_type"] != "refresh_token")
            {
                context.SetError("invalid_request");

                this.options.Logger.Error("Redirect URI was not specified, the token request is not valid");

                return;
            }

            if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
                context.TryGetFormCredentials(out clientId, out clientSecret))
            {
                // Only proceed if client id and client secret is provided
                if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
                {
                    context.SetError("invalid_client");

                    this.options.Logger.WarnFormat("Client id ({0}) or client secret ({1}) is invalid", clientId, clientSecret);

                    return;
                }

                this.options.Logger.DebugFormat("Authenticating client '{0}'", clientId);

                var client = await this.options.ClientManager.AuthenticateClientCredentialsAsync(clientId, clientSecret);

                if (!client.Identity.IsAuthenticated)
                {
                    context.SetError("invalid_grant");

                    this.options.Logger.WarnFormat("Client '{0}' was not authenticated because the supplied secret did not match", clientId);

                    return;
                }
            }
            else
            {
                context.SetError("invalid_client");

                this.options.Logger.WarnFormat("Client '{0}' was not authenticated because the provider could not retrieve the client id and client secret from the Authorization header or Form parameters", clientId);

                return;
            }

            context.OwinContext.GetOAuthContext().ClientId    = context.ClientId;
            context.OwinContext.GetOAuthContext().RedirectUri = context.Parameters["redirect_uri"];
            context.OwinContext.GetOAuthContext().Scope       = context.Parameters["scope"]?.Split(' ');

            this.options.Logger.DebugFormat("Client '{0}' was successfully authenticated", clientId);

            context.Validated(clientId);
        }
        // OAuthAuthorizationServerProvider sınıfının client erişimine izin verebilmek için ilgili ValidateClientAuthentication metotunu override ediyoruz.
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            //Burada client validation kullanmadık. İstersek custom client tipleri ile client tipine görede validation sağlayabiliriz.

            context.Validated();
        }
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     return(Task.FromResult(context.Validated()));
 }
Exemplo n.º 17
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     // OAuth2 supports the notion of client authentication
     // this is not used here
     context.Validated();
 }
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     // OAuthAuthorizationServerProvider sınıfının client erişimine izin verebilmek için ilgili ValidateClientAuthentication metotunu override ediyoruz.
     context.Validated();
 }
Exemplo n.º 19
0
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     return(Task.Run(() => context.Validated()));
 }
Exemplo n.º 20
0
 #pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 #pragma warning restore CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
 {
     context.Validated();
 }
Exemplo n.º 21
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     await Task.FromResult(0);
 }
Exemplo n.º 22
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     await Task.Run(() => context.Validated());
 }
Exemplo n.º 23
0
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            await Task.FromResult <dynamic>(new { });

            context.Validated();
        }
Exemplo n.º 24
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     await Task.Factory.StartNew(() => context.Validated());
 }
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            //await Task.Factory.StartNew(() =>
            //{
            //    context.Validated();
            //});

            //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/secrets once access tokens are obtained
            //    context.Validated();
            //    //context.SetError("invalid_clientId", "ClientId should be sent.");
            //    return Task.FromResult<object>(null);
            //}

            //client = _authRepository.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 != clientSecret.GetHash())
            //        {
            //            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));
        }
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     login_type = context.Parameters.Where(x => x.Key == "login_type").Select(f => f.Value).FirstOrDefault()[0];
 }
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            // Les informations d'identification du mot de passe du propriétaire de la ressource ne fournissent pas un ID client.

            context.Validated();
        }
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
     //context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });  // <-- This is the line you need
     context.Validated();
 }
Exemplo n.º 29
0
 public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
 }
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     context.Validated();
     context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
     return(Task.FromResult <object>(null));
 }