Example #1
0
        private async Task AttachUserToContext(HttpContext context, string accessCode,
                                               IAccessTokenService accessTokenService, IUserApplicationService userApplicationService)
        {
            AccessToken accessToken = await accessTokenService.FindByCodeAsync(accessCode);

            if (accessToken.Revoked || DateTime.Now > accessToken.ExpiresAt)
            {
                return;
            }

            context.Items["User"]        = accessToken.User;
            context.Items["Application"] = accessToken.Application;

            if (accessToken.Application != null)
            {
                List <Scope>    scopes          = new List <Scope>();
                UserApplication userApplication =
                    await userApplicationService.FindByUserAndApplicationAsync(accessToken.User,
                                                                               accessToken.Application);

                if (userApplication == null)
                {
                    return;
                }

                foreach (UserApplicationScope scope in userApplication.Scopes)
                {
                    scopes.Add(scope.Scope);
                }

                context.Items["Scopes"] = scopes;
            }
        }