public async Task <ResourceContext> CreateResourceContextAsync(HttpContext httpContext, ResourceEndpoint resourceEndpoint) { Guard.ArgumentNotNull(httpContext, nameof(httpContext)); Guard.ArgumentNotNull(resourceEndpoint, nameof(resourceEndpoint)); string protectedAccessToken = await _tokenAccessor.GetAccessTokenAsync(httpContext); if (string.IsNullOrEmpty(protectedAccessToken)) { return(new ResourceContext(httpContext, OAuthErrors.UnauthorizedClient.MissingAccessToken.Format())); } var ticket = _ticketFormat.Unprotect(protectedAccessToken); if (null == ticket) { return(new ResourceContext(httpContext, OAuthErrors.InvalidGrant.InvalidAccessToken.Format())); } return(new ResourceContext(httpContext, ticket, resourceEndpoint)); }
public ResourceContext(HttpContext httpContext, OAuthTicket oAuthTicket, ResourceEndpoint resourceEndpoint) : base(httpContext) { OAuthTicket = oAuthTicket ?? throw new ArgumentNullException(nameof(oAuthTicket)); ResourceEndpoint = resourceEndpoint ?? throw new ArgumentNullException(nameof(resourceEndpoint)); Scopes = oAuthTicket.Scopes.Intersect(resourceEndpoint.Scopes).ToArray(); }