Esempio n. 1
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))
            });
        }
Esempio n. 2
0
        [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))
            });
        }