ios-nd-networking icon indicating copy to clipboard operation
ios-nd-networking copied to clipboard

Use an alternative for storing API key in TMDB Client.

Open OwenLaRosa opened this issue 6 years ago • 3 comments

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.

  • Store it in a separate file (Plist, JSON, etc.) that's stored on the device.
  • Move its constant to a Swift file that's ignored by version control.

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.

OwenLaRosa avatar Nov 09 '18 22:11 OwenLaRosa

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

Created a plist for API Key. ☺️

sean-williams24 avatar Aug 06 '19 11:08 sean-williams24

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

EdwardPhaniOS avatar Sep 04 '21 13:09 EdwardPhaniOS

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: ""])".

kvyavorskiy avatar Jan 01 '22 13:01 kvyavorskiy