Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OwenLaRosa opened this issue Nov 9, 2018 · 3 comments
Open

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

OwenLaRosa opened this issue Nov 9, 2018 · 3 comments
Labels
moviemanagerchallenge Task for "Improve the Movie Manager" Challenge

Comments

@OwenLaRosa
Copy link
Contributor

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 OwenLaRosa added the moviemanagerchallenge Task for "Improve the Movie Manager" Challenge label Nov 9, 2018
@sean-williams24
Copy link

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

Created a plist for API Key. ☺️

@EdwardPhaniOS
Copy link

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
Copy link

ghost commented Jan 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
moviemanagerchallenge Task for "Improve the Movie Manager" Challenge
Projects
None yet
Development

No branches or pull requests

3 participants