udacity / ios-nd-networking

Resources for Udacity's iOS Networking with Swift course.
MIT License
173 stars 89 forks source link

Use an alternative for storing API key in TMDB Client. #5

Open OwenLaRosa opened 5 years ago

OwenLaRosa commented 5 years ago

When first committing the Movie Manager code, I accidentally left my API key in the TMDBClient.swift file. Oops! This is a common mistake, especially when the API key is in the same file that's being edited frequently.

We shouldn't leave our API key in version control, and there are a variety of (non-perfect) ways to address this.

And there are others. But since we want to keep the key private to ourselves, it's definitely not a good idea to store it in TMDBClient.swift, and we should try to find a better place to put it.

sean-williams24 commented 5 years ago

https://github.com/sean-williams24/The-Movie-Manager.git

Created a plist for API Key. ☺️

EdwardPhaniOS commented 3 years ago

Step 1: Create a plist file name "Secret.plist" Step 2: Add API key to plist file as API_KEY = [YOUR_API_KEY] Step 3: Add "Secret.plist" to git ignore

ghost commented 2 years ago

We might as well store our api key to the environment variables. Step 1: Open Xcode's scheme editor. Step 2: Select Run/Arguments in the editor. Step 3: Add apiKey entry for the Name, and your api key string for the Value. Step 4: In the TMDBClient, remove your apiKey static variable, and in the Endpoints enum change apiKeyParam to this: static let apiKeyParam = "?api_key=\(ProcessInfo.processInfo.environment["apiKey", default: ""])".