dj-rest-auth와 django-allauth를 사용하여 소셜 로그인 및 회원가입을 구현하는데 카카오와 깃허브는 정상적으로 잘 되는데 구글의 경우는 에러가 발생하는 상황이 일어났다.
에러코드
문제가 되는 부분은 accept를 받아오는 부분인데
response["id_token"],
TypeError: string indices must be integers
에러로 response가 딕셔너리가 아니라 string여서 status가 500 에러가 발생하였다.
dj-rest-auth부터 거진 한 달 동안 이 에러를 찾아다녔는데 django-allauth의 0.52.0의 버전 문제였다.
(사실문제를 첫날에 문제를 파악했지만 버전다운이 최후의 선택이라 생각해서 기존 버전을 유지한 채로 진행하는 게 맞다고 생각했다)
allauth 라이브러리의 googleOAuth2Adapter클래스가 바뀌었음
0.52.0 (2022-12-29)
Note worthy changes
- Officially support Django 4.1.
- New providers: OpenID Connect, Twitter (OAuth2), Wahoo, DingTalk.
Introduced a new provider setting OAUTH_PKCE_ENABLED that enables the PKCE-enhanced Authorization Code Flow for OAuth 2.0 providers.
- When ACCOUNT_PREVENT_ENUMERATION is turned on, enumeration is now also prevented during signup, provided you are using mandatory email verification. There is a new email template (templates/account/email/acccount_already_exists_message.txt) that will be used in this scenario.
- Updated URLs of Google's endpoints to the latest version; removed a redundant userinfo call.
- Fixed Pinterest provider on new api version.
googleOAuth2Adapter을 커스텀으로 만들어 보기도 하고 데이터를 수정해서 넣어보기도 했지만 나의 수준에서는 도저히 해결할 수 없는 문제라고 생각했고 아무리 시간이 남아도는 학생이라지만 로그인을 너무 오래 붙잡고 있는 것도 안 되겠다 생각해서 질문을 하기로 결심하고 질문을 했다.
답변은 생각보다 간단했지만 정말 내가 잘못생각했구나 라는걸 느꼈다.
패키지를 수정하거나 버전을 내리거나 해당 메소드를 우회하는 방법이 있다는 답변과 함께 권장 버전이 괜히 있는 게 아니라는 이야기를 들었다. 권장과 최신은 다른 것이라는 말이다. 최신 = 베타 버전이라고 생각해야 한다는 것이다.
나는 최신 버전을 쓰는 게 당연하고 최후의 보루로 버전다운이라 생각했는데 아예 틀렸던 것이다.
반대로 버전 업그레이드가 최후의 수단이라고 말씀해 주셨다. 업데이트를 한다는 건 이후 책임은 본인이 진다는 말이고 업데이트를 하는 이유가 단지 최신버전이 나왔다는 이유라면 업데이트를 하면 안 된다라는 것이다.
결국 나는 버전 다운을 진행하였다. - 당연히 정상적으로 작동했다.
pipenv install django-allauth==0.51.0
아래의 레퍼런스는 내가 찾아본 것 중 극히 일부지만 분명 도움이 될 것이라고 생각한다.
Reference
fix(google): Avoid id_token error after allauth upgrade by luchinke · Pull Request #482 · iMerica/dj-rest-auth
After the latest upgrade from 'allauth' package, the registration serializer is not passing the correct values to properly login with google.
github.com
Fix Google login with auth code flow by c-w · Pull Request #488 · iMerica/dj-rest-auth
In #482 a regression was introduced for logging in with Google using the auth-code flow: Traceback (most recent call last): File "/venv/lib/python3.11/site-packages/allauth/socialaccount/provider...
github.com
fix(google): oauth id token parse issue on updated Google spec by suhjohn · Pull Request #3278 · pennersr/django-allauth
Submitting Pull Requests General Make sure you use semantic commit messages. Examples: "fix(google): Fixed foobar bug", "feat(accounts): Added foobar feature". All Python code must formatted usi...
github.com
GitHub - iMerica/dj-rest-auth: Authentication for Django Rest Framework
Authentication for Django Rest Framework. Contribute to iMerica/dj-rest-auth development by creating an account on GitHub.
github.com
GitHub - pennersr/django-allauth: Integrated set of Django applications addressing authentication, registration, account managem
Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication. - GitHub - pennersr/django-allauth: Integrate...
github.com
[DRF] 구글 소셜 로그인 TypeError: string indices must be integers 에러
구글 소셜로그인 복습중에 TypeError: string indices must be integers 라는 에러가 발생하였다.인덱스에 정수형을 넣지 않아서 발생하는 오류인데똑같이 코드를 작성했음에도 배포사이트에선 오류가 없
velog.io
'Django > DRF' 카테고리의 다른 글
Django SSE 이용해서 알람 기능 구현 (2) (1) | 2023.10.19 |
---|---|
Django SSE 이용해서 알람 기능 구현 (1) (0) | 2023.10.18 |
DRF Paginator를 이용한 페이지네이션 (0) | 2023.10.11 |
DRF 유저 정보로 JWT 토큰 발급 (0) | 2023.10.11 |
Django JWT를 이용한 소셜로그인 (백엔드) (0) | 2023.10.11 |