금융 경제 보험 정보

[flutter] MAPBOX 비밀 토큰 권한 문제 본문

카테고리 없음

[flutter] MAPBOX 비밀 토큰 권한 문제

정보캣 2024. 4. 27. 15:51

 

 

아우....

맵박스를 이용해서 플러터에 맵을 띄우려고 앱을 개발하던 중

 이틀 동안 발목이 잡혀서.....허우적 거린 게 있는데...

바로 맵박스에서 비밀 토큰 권한 해결을 못해서 계속 pod install 에서 에러가 난것이었다

Analyzing dependencies
Downloading dependencies
Installing Flutter (1.0.0)
Installing Mapbox-iOS-SDK (6.4.1)

[!] Error installing Mapbox-iOS-SDK
[!] /opt/local/bin/curl -f -L -o /var/folders/5c/bm3hqc3d2qs3qmf_m35c6myr0000gn/T/d20240427-97454-3uhoze/file.zip https://api.mapbox.com/downloads/v2/mobile-maps/releases/ios/packages/6.4.1/mapbox-ios-sdk-dynamic.zip --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.15.2 cocoapods-downloader/2.1'

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   267    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 401

 

진짜 위의 에러만 수백번은 본 듯....

공식 문서에 따라서 차근차근 했으면 되는데

또또 급한성격에....이것저것 막 해보다가 시간만 더끌었네 

 

Configure credentials

 
Note

If you plan to install the SDK via direct download, you do not need to configure a secret token. You will still need to configure a public token.

Before installing the SDK, you will need to gather the appropriate credentials. The SDK requires two pieces of sensitive information from your Mapbox account. If you don't have a Mapbox account: sign up and navigate to your Account page. You'll need:

  • A public access token: From your account's tokens page, you can either copy your default public token or click the Create a token button to create a new public token.
  • A secret access token with the Downloads:Read scope.
    1. From your account's tokens page, click the Create a token button.
    2. From the token creation page, give your token a name and make sure the box next to the Downloads:Read scope is checked.
    3. Click the Create token button at the bottom of the page to create your token.
    4. The token you've created is a secret token, which means you will only have one opportunity to copy it somewhere secure.

You should not expose these access tokens in publicly-accessible source code where unauthorized users might find them. Instead, you should store them somewhere safe on your computer and make sure they're only added when your app is compiled. Once this configuration step has been completed, you will be able to reference your credentials in other parts of your app.

Configure your secret token

Your secret token enables you to download the SDK directly from Mapbox. To use your secret token, you will need to store it in a .netrc file in your home directory (not your project folder). This approach helps avoid accidentally exposing your secret token by keeping it out of your application's source code. Depending on your environment, you may have this file already, so check first before creating a new one.

The .netrc file is a plain text file that is used in certain development environments to store credentials used to access remote servers. The login should always be mapbox. It should not be your personal username used to create the secret token. To set up the credentials required to download the SDK, add the following entry to your .netrc file:

machine api.mapbox.com
login mapbox
password YOUR_SECRET_MAPBOX_ACCESS_TOKEN
 

Configure your public token

To configure your public access token, you will need to add a MGLMapboxAccessToken key to Info.plist and set the value to your public access token.

For projects created in Xcode 13 and higher, Info.plist is automatically generated. Configure your public access token by clicking on the project name in the project navigator to open the project editor, selecting a target, switching to the Info pane, and adding MGLMapboxAccessToken and your public access token as a new key-value pair in Custom iOS Target Properties.

If you ever need to rotate your access token, you will need to update the token value in your Info.plist or Info pane file.

 

 

공식 문서에 보면 이렇게 친절하게 잘 나와있다..ㅡㅡ

1. 비밀 토큰을 만든다 (Create Token)

2. 비밀 토큰 정보는  .netrc file 파일에 저장한다

3. 퍼블릭 토큰 정보는 Info.plist 에 저장한다.

 

결과적으로 내가 잘못했던건 .netrc file 파일에 퍼블릭 토큰 정보를 저장하고 계속 실행하는 삽질했다.ㅡ.ㅡ;

 

netrc file 을 만드는 방법은 

맥기준으로 터미널을 열고 

nano .netrc 이렇게 열고나서 

machine api.mapbox.com
login mapbox
password "여러분의 비밀 토큰 꼭꼭꼭"

 

이렇게 입력하고 

ctrl x -> YES -> enter 

 

그리고 pod install 을 하니

 

Analyzing dependencies
Downloading dependencies
Installing Flutter (1.0.0)
Installing Mapbox-iOS-SDK (6.4.1)
Installing MapboxAnnotationExtension (0.0.1-beta.2)
Installing MapboxMobileEvents (0.10.14)
Installing mapbox_gl (0.0.1)
Generating Pods project
Integrating client project
Pod installation complete! There are 2 dependencies from the Podfile and 5 total pods installed.

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).

 

이렇게 성공했다 

아우 개빡쳐!!!

Comments