public Task <LoginRequest> Create(LoginRequestReason reason, long userId, long?groupChatId, long privateChatId, string trackId = null) { return(_loginRequestRepository.Upsert(new LoginRequest { UserId = userId, Id = Guid.NewGuid().ToString(), ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(_loginRequestExpiresInMinutes), GroupChatId = groupChatId, PrivateChatId = privateChatId, TrackId = trackId, Reason = reason })); }
/// <summary> /// Get an url to the spotify login web page, where we can authorize our bot. /// </summary> /// <returns>The url to the spotify login page.</returns> public async Task <Uri> CreateLoginRequest(long userId, LoginRequestReason reason, long?groupChatId, long privateChatId, string trackId = null) { var loginRequest = await _loginRequestService.Create(reason, userId, groupChatId, privateChatId, trackId); // Make sure we can add tracks to the queue for all users. var scopes = new List <string> { Scopes.UserModifyPlaybackState }; // For group chats or the LoginLink command also request access to playlists, so we can add tracks. if (reason == LoginRequestReason.AddBotToGroupChat || reason == LoginRequestReason.LoginLinkCommand) { scopes.AddRange(new [] { Scopes.PlaylistModifyPrivate, Scopes.PlaylistModifyPublic }); } return(new SpotifyAPI.Web.LoginRequest(GetCallbackUri(), _spotifyOptions.ClientId, SpotifyAPI.Web.LoginRequest.ResponseType.Code) { Scope = scopes, State = loginRequest.Id }.ToUri()); }