When I give the API Token value in my project and try to send it to github, I get an error

Yalçın Mete 80 Reputation points
2024-09-24T18:42:41.6633333+00:00

Hi Masters,

I am a beginner in .net Core. If you allow me, I would like to ask a question.

In the training videos I have watched, the instructor was able to add the API Key to the source file and upload it to github, but when I try to do it, I get an error.

I know that publishing the API Key information on github is not correct, but I wonder why I get an error when I fill in the API Key information and try to send it to github.

I get an error when I give the API Token value in my project and try to send it to github. Is there such a control in Visual Studio?

API Key information is empty :
User's image

Commit operation.User's image

Push operation . I don't get any errors.
User's image

I add the API Key information and then I commit.
User's image

I am doing a push operation and getting an error.
User's image

Project versions:User's image

User's image

I don't think the error occurred because I added the API Key information, but when I do this, I get an error and I don't understand why this is happening.

I closed and reopened Visual Studio.

I updated Visual Studio.

I restarted my computer.

But the problem is still not solved.

Project github address:
https://github.com/yalcinmete/ShopApp/blob/master/ShopApp.WebUI/EmailServices/EmailSender.cs

https://github.com/yalcinmete/ShopApp
ShopApp.WebUI/EmailServices/EmailSender.cs

Can you help me?

Thanks

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,877 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
GitHub Training
GitHub Training
GitHub: A web-based hosting service for software development and version control using Git. Acquired by Microsoft in 2018.Training: Instruction to develop new skills.
45 questions
{count} votes

Accepted answer
  1. Pradeep M 3,680 Reputation points Microsoft Vendor
    2024-09-25T04:19:46.74+00:00

     Hi Yalçın Mete,

    Thank you for reaching out to Microsoft Q & A forum.

    The error you’re experiencing may be related to GitHub’s security policies, which actively scan repositories for sensitive information, such as API tokens. If GitHub detects sensitive data, it may block the push to prevent accidental exposure. 

    To address this issue, here are a few recommendations: 

    1.Remove the API Key from your source code: Instead of hardcoding the API key into your project files, consider storing it securely using environment variables or a secrets management tool. In .NET Core, for example, you can store sensitive data in appsettings.json for local development and use environment variables in production. 

    2.Add sensitive files to .gitignore: To prevent committing files with sensitive information, ensure that such files (like appsettings.json) are listed in the .gitignore file so they won’t be tracked or pushed to GitHub. 

    3.Review GitHub’s Secret Scanning: GitHub may have detected the API key and blocked the push as a security measure. You can check the Security tab in your GitHub repository for any alerts or warnings related to this. 

    Additionally, you can review the output window in Visual Studio for more detailed error messages. Here’s a guide from Microsoft on pushing to a remote Git repository using Visual Studio: Git push to remote repository in Visual Studio

    If the issue persists after these steps, please provide the error message from the output window, as this will help me give you more specific assistance. 

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.       

    Thank you. 

     

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,576 Reputation points
    2024-09-24T19:06:09.5533333+00:00

    In the output window select “source control - git” to see the error. You probably need to do a pull.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.