/*--------------------------------------------------------------------------------------------*/
        public OauthLoginResult ExecuteScope(IOperationContext pOpCtx, IOauthLoginTasks pTasks,
                                             string pClientId, string pRedirUri, bool pAllowScope)
        {
            App app = ValidateAndGetApp(pOpCtx, pTasks, pClientId, pRedirUri);

            if (pOpCtx.Auth.CookieUserId == null)
            {
                throw pTasks.NewFault(LoginErrors.access_denied, LoginErrorDescs.NotLoggedIn);
            }

            //The member may not be ready immediately after the first login.
            var    sw     = Stopwatch.StartNew();
            long   userId = (long)pOpCtx.Auth.CookieUserId;
            Member mem    = null;

            while (mem == null)
            {
                if (sw.ElapsedMilliseconds > 10000)
                {
                    pTasks.NewFault(LoginErrors.server_error, LoginErrorDescs.Unexpected);
                }

                mem = pTasks.GetMember(pOpCtx.Data, app.VertexId, userId);

                if (mem == null)
                {
                    Thread.Sleep(200);
                }
            }

            if (!pAllowScope)
            {
                pTasks.DenyScope(pOpCtx.Data, mem);
                throw pTasks.NewFault(LoginErrors.access_denied, LoginErrorDescs.AccessDeny);
            }

            pTasks.UpdateGrant(pOpCtx, mem, pRedirUri);

            return(new OauthLoginResult {
                Redirect = pRedirUri,
                Code = mem.OauthGrantCode
            });
        }