마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

webview를 통한 oauth 2.0기반 연결 400 error

0 추천

안녕하세요

MS band라는 기기에 api를 통해 데이터를 받아오려고 합니다.

https://developer.microsoftband.com/Content/docs/MS%20Health%20API%20Getting%20Started.pdf 에서 참고하고 샘플앱을 참고하면서 진행하였습니다.

흐름은 https://apps.dev.microsoft.com/ 에서

MS 어플리케이션을 등록해 client_id와 client_secret 그리고 redirect_uri를 받고

GET해서 authentication code를 받아오고

이 코드를 이용해서 POST하여 엑세스토큰이랑 리프레시토큰을 얻는거였습니다.

소스는 샘플앱이 있어서 거기에 해당기능만 갖다 끌어다 썻습니다.

authentication code까지는 받아졌습니다.

문법을 맞추어서 POST를 하였지만 POST를 하여 InputStream을 받으면 에러가 떠 자꾸 ErrorStream만 자꾸 받네요....

오류가 났던 소스입니다.

try {
            URL u = new URL(url);

            HttpURLConnection conn = (HttpURLConnection) u.openConnection();
            conn.setReadTimeout(10000);
            conn.setConnectTimeout(15000);
            conn.setRequestMethod("POST");
            //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setDoInput(true);
            conn.connect();
            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                is = conn.getErrorStream();
                Log.d(TAG, "downloadUrl: 에러");
            } else {
                is = conn.getInputStream();
                Log.d(TAG, "downloadUrl: 성공");
            }


            return readIt(is, 9999);
        } finally {
            Log.d(TAG, "downloadUrl: ㅇㅇ");
            if (is != null) {
                is.close();
            }
        }

 

디버그 창은 이렇게 뜨네요...

02-07 16:28:24.945 27831-28437/com.example.user.bandsample I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-07 16:28:24.945 27831-28437/com.example.user.bandsample I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-07 16:28:25.895 27831-27831/com.example.user.bandsample W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 27831
02-07 16:28:26.105 27831-28437/com.example.user.bandsample D/WebviewActivity: downloadUrl: 에러
02-07 16:28:26.105 27831-28437/com.example.user.bandsample D/WebviewActivity: downloadUrl: ㅇㅇ
02-07 16:28:26.105 27831-27831/com.example.user.bandsample D/WebviewActivity: onPostExecute: {"error":"invalid_client","error_description":"The provided request must include a 'client_id' input parameter."}������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

 

이ㅡ글 (240 포인트) 님이 2017년 2월 8일 질문
해당 url 로 아무값도 안보냈는데 get으로는  authentication code 받아오셨다는건가여? 로그만보면 해당 url로 값 을 안보내서 생긴 에러인거같습니다.
GET을 할때 Mc49f0de4-c03f-df8d-f2eb-921b41fe3c1e라는 코드를 받고

02-08 18:16:32.594 16527-16838/com.example.user.bandsample D/WebviewActivity: downloadUrl dd: https://login.live.com/oauth20_token.srf?client_id=0d5f6f03-17b4-4b6b-a854-774fd5eebd61&redirect_uri=https://login.live.com/oauth20_desktop.srf&client_secret=BmPr8iuxhcqo5BJbqGBJbcP&code=Mc49f0de4-c03f-df8d-f2eb-921b41fe3c1e&grant_type=authorization_code
라는 url를 보냈는데... 정말 모르겠네요...
....get에서는 해당 url 로 넘겨주어서 정상적으로 값을 받으신거고 post 로 보내실거면 client_id 등 key값을  parameter  로 넘겨서 보내주셔야되여 http://webs.co.kr/?document_srl=365338  참고해보세여
덕분에 받아지긴 했습니다... 근데 문제가
{"error":"invalid_request","error_description":"Public clients can't send a client secret."}
로 나오네요 client_secret을 지우면 access token만 받아옵니다.
제가 지금 public client로 줍니다. refresh token을 받는 작업을 수행하기 위해서는 confident client로 걸어 주어야 할 같은데 따로 연결방법이 있나요??

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...