본문 바로가기

설치&설정 관련

npm repository 사용시 인증(로그인) 처리 방법

728x90

npm repository 사용시 인증(로그인) 처리 방법

Nexus 설치 및 설정을 후 보안의 사유로 계정 로그인 처리를 찾아보다 .npmrc파일에 _auth를 이용해서 로그인 처리를 알게 되었습니다.

.npmrc 파일은 아래와 같은 key를 가지고 있습니다.

# Nexus proxy registry pointing to http://registry.npmjs.org/
registry = https://<host>/nexus/content/repositories/npmjs-registry/ 

# base64 encoded authentication token
_auth = <see question below>

# required by Nexus
email = <valid email>

# force auth to be used for GET requests
always-auth = true

# we don't want to put certificates in .npmrc
strict-ssl = false

# log level - Logging Level은 error / warn / info / http / verbose / debug / silly 로 오른쪽으로 갈 수록 많이 표기 됩니다.
loglevel = silly

.npmrc 에서 base64로 계정 정보(ID/PW)를 이용한 Token을 _auth에 넣으면 자동으로 로그인이 됩니다.

base64를 이용한 Token 생성방법은 아래와 같습니다.

$ echo -n 'username:password' | openssl base64

결과 값을 _auth에 삽입 후 npm install을 명령어를 이용하면 로그인이 자동으로 처리 되어서 편리합니다.

참고자료

태그