Exemplo n.º 1
0
        private async Task <AuthorizeViewModel> FillFromRequest(OpenIdConnectRequest OIDCRequest)
        {
            string      clientId = OIDCRequest.ClientId;
            OAuthClient client   = await _context.ClientApplications.FindAsync(clientId);

            if (client == null)
            {
                return(null);
            }
            else
            {
                // Get the Scopes for this application from the query - disallow duplicates
                ICollection <OAuthScope> scopes = new HashSet <OAuthScope>();
                if (!String.IsNullOrWhiteSpace(OIDCRequest.Scope))
                {
                    foreach (string s in OIDCRequest.Scope.Split(' '))
                    {
                        if (OAuthScope.NameInScopes(s))
                        {
                            OAuthScope scope = OAuthScope.GetScope(s);
                            if (!scopes.Contains(scope))
                            {
                                scopes.Add(scope);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                AuthorizeViewModel avm = new AuthorizeViewModel()
                {
                    ClientId     = OIDCRequest.ClientId,
                    ResponseType = OIDCRequest.ResponseType,
                    State        = OIDCRequest.State,
                    Scopes       = String.IsNullOrWhiteSpace(OIDCRequest.Scope) ? new string[0] : OIDCRequest.Scope.Split(' '),
                    RedirectUri  = OIDCRequest.RedirectUri
                };

                return(avm);
            }
        }