コード例 #1
0
        public async Task <ActionResult <AuthenticateResponse> > AuthDiscordAsync(AuthenticateDiscordRequest request)
        {
            var user = User = await _discord.GetOrCreateUserAsync(request.Code);

            return(new AuthenticateResponse
            {
                Token = await _auth.GenerateTokenAsync(user),
                User = ProcessUser(user.Convert(_services))
            });
        }
コード例 #2
0
        public async Task <UserController.AuthenticateResponse> GetOrCreateDiscordUserAsync(GetOrCreateDiscordUserRequest request)
        {
            var user = await _discord.GetOrCreateUserAsync(new DiscordOAuthUser
            {
                Id            = ulong.Parse(request.Id),
                Username      = request.Username,
                Discriminator = request.Discriminator,

                // optional
                Locale = request.Locale,
                Email  = request.Email
            });

            return(new UserController.AuthenticateResponse
            {
                Token = await _auth.GenerateTokenAsync(user),
                User = ProcessUser(user.Convert(_services))
            });
        }
コード例 #3
0
ファイル: InternalController.cs プロジェクト: t6tg/nhitomi
        [HttpPost("auth/discord", Name = "getOrCreateUserDiscord"), RequireUser(Permissions = UserPermissions.CreateUsers)] // no RequireDbWrite
        public async Task <UserController.AuthenticateResponse> GetOrCreateDiscordUserAsync(GetOrCreateDiscordUserRequest request)
        {
            // RequireDbWrite is missing because it's probably better for some user information to get lost, than to block this route which nhitomi-discord critically depends on

            var user = await _discord.GetOrCreateUserAsync(new DiscordOAuthUser
            {
                Id            = ulong.Parse(request.Id),
                Username      = request.Username,
                Discriminator = request.Discriminator,

                // optional
                Locale = request.Locale,
                Email  = request.Email
            });

            return(new UserController.AuthenticateResponse
            {
                Token = await _auth.GenerateTokenAsync(user),
                User = ProcessUser(user.Convert(_services))
            });
        }