솜은 코튼

[error] 403. Error: disallowed_useragent. 본문

Android/오류사항

[error] 403. Error: disallowed_useragent.

솜.코 2021. 1. 5. 10:37

[오류 사항]

 

403. Error: disallowed_useragent.
Google can't sign you safety inside this app. You can use Google sign-in by visiting this app's website in a browser like Safari or Chrome.

 

 

[오류 원인]

WebView로 된 인앱 브라우저로 Google OAuth 2.0 링크를 여는 경우

 

Android OS에서 구글 인증을 Web방식으로 할 때 발생.

구글이 2016년 10월 20일부터 WebView로 구글 인증을 하지 못하도록 막았기 때문이다.

 

[해결 방법]

구글 인증 링크를 WebView로 구현된 인앱 브라우저가 아닌 ChromeCustomTabs로 열거나,

WebView를 열 때 user-agent를 변경하여 우회한다.

 

1) ChromeCustomTabs 사용 방법

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Uri uri = Uri.parse("[호출할 url]");
 
            
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
 
// Begin customizing
// Set toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(callerObject, R.color.browser_actions_bg_grey));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(callerObject, R.color.browser_actions_bg_grey));
 
// set start and exit intent
CustomTabsIntent customTabsIntent = intentBuilder.build();
 
// launch the url
// customTabsIntent.launchUrl(MainActivity, uri);
customTabsIntent.launchUrl(callerObject, uri);
cs

 

1) user-agent를 변경하여 우회하는 방법

1
2
String USER_AGENT = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19";
webview.getSettings().setUserAgentString(USER_AGENT);
cs