DRF 구글 소셜로그인 TypeError: string indices must be integers

2023. 10. 12. 15:28· Django/DRF
목차
  1. 에러코드
  2. Reference
반응형

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
  1. 에러코드
  2. Reference
'Django/DRF' 카테고리의 다른 글
  • Django SSE 이용해서 알람 기능 구현 (2)
  • Django SSE 이용해서 알람 기능 구현 (1)
  • DRF Paginator를 이용한 페이지네이션
  • DRF 유저 정보로 JWT 토큰 발급
Jong_seoung
Jong_seoung
기록하자, 머리는 생각하는 곳이지 저장장치가 아니다.
반응형
Jong_seoung
Today_developStory
Jong_seoung
전체
오늘
어제

블로그 메뉴

  • Home
  • Git Hub
  • 분류 전체보기 (350)
    • Theory (16)
    • Java (3)
      • 알고리즘 (2)
      • 문법 (0)
    • Spring (7)
      • 스프링 입문 (6)
      • PickTalk (0)
      • 에러처리 (1)
    • Python (80)
      • 알고리즘 - 이론 (17)
      • 알고리즘 - 내장함수, 라이브러리 등등 (3)
      • 알고리즘 - 백준 (53)
      • 나도코딩 정리 (2)
      • 기타 (5)
    • Django (159)
      • DRF (105)
      • 인프라 (46)
      • DataBases (2)
      • API Docs (6)
    • FrontEnd (22)
      • htmx (2)
      • React (8)
      • 자바스크립트 (12)
    • GIT (16)
    • 기타 (8)
      • 정리 (2)
      • Flutter (1)
      • 마이크로프로세서 - ATmega128 (2)
      • 개발환경 세팅 (3)
    • 자격증 (37)
      • 정보처리기사 (19)
      • SQLD자격증 (18)

인기 글

최근 글

태그

  • alarm
  • BFS
  • CSRF
  • Django
  • django channels
  • django sse
  • django tutorial
  • django 배포
  • django 스웨거 적용
  • Django 이미지 저장

최근 댓글

hELLO · Designed By 정상우.v4.3.0
Jong_seoung
DRF 구글 소셜로그인 TypeError: string indices must be integers
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.