Exemplo n.º 1
0
        /// <summary>
        /// Check if the specified client ID is valid.
        /// </summary>
        /// <param name="context">The authorization endpoint specific context.</param>
        /// <returns>A <see cref="Task{Application}"/> whose result represents the specified client ID specific application. </returns>
        /// <exception cref="ArgumentNullException">Specified <paramref name="context"/> is null.</exception>
        protected virtual async Task <Application> ValidateClientIdAsync(OAuthContext context)
        {
            Guard.ArgumentNotNull(context, nameof(context));
            var clientId = ((context as AuthorizationContext)?.ClientId)
                           ?? (context as TokenContext)?.ClientId;

            if (string.IsNullOrEmpty(clientId))
            {
                return(null);
            }
            var application = await ApplicationStore.GetByClientIdAsync(clientId);

            if (null == application)
            {
                context.Failed(OAuthErrors.UnauthorizedClient.UnregisteredApplication, clientId);
            }
            return(application);
        }