· 6 years ago · Jan 27, 2019, 03:00 PM
1public class NetworkService {
2 private static NetworkService mInstance;
3 private static final String BASE_URL = "https://oauth.yandex.ru";
4 private Retrofit mRetrofit;
5 private static final String ID = "здеÑÑŒ мой id";
6 private static final String PASSWORD = "здеÑÑŒ мой пароль";
7 private static final String CALLBACK_URI = "здеÑÑŒ колбÑк";
8
9 private NetworkService() {
10 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
11 interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
12 Gson gson = new GsonBuilder()
13 .setLenient()
14 .create();
15 OkHttpClient.Builder client = new OkHttpClient.Builder()
16 .addInterceptor(interceptor);
17
18 mRetrofit = new Retrofit.Builder()
19 .baseUrl(BASE_URL)
20 .addConverterFactory(GsonConverterFactory.create(gson))
21 .client(client.build())
22 .build();
23
24 }
25
26 public static NetworkService getInstance() {
27 if (mInstance == null) {
28 mInstance = new NetworkService();
29 }
30 return mInstance;
31 }
32
33 public ApiService getJSONApi() {
34 return mRetrofit.create(ApiService.class);
35 }
36
37
38 public static void puk() {
39 Call<AccessCodeYandex> call = NetworkService.getInstance().getJSONApi().getToken( ID);
40
41 call.enqueue(new Callback<AccessCodeYandex>() {
42 @Override
43 public void onResponse(Call<AccessCodeYandex> call, Response<AccessCodeYandex> response) {
44 System.out.println();
45 }
46
47 @Override
48 public void onFailure(Call<AccessCodeYandex> call, Throwable t) {
49 System.out.println();
50 }
51 });
52 }
53}
54
55public interface ApiService {
56 @POST("/authorize?response_type=code")
57 @FormUrlEncoded
58 Call<AccessCodeYandex> getToken1(@Field("client_id") String client_id);
59}
60
61@NoArgsConstructor
62@Getter
63@Setter
64public class AccessCodeYandex {
65 @SerializedName("code")
66 @Expose
67 private String code;
68 @SerializedName("state")
69 @Expose
70 private String state;
71}
72
73D/OkHttp: <-- 200 OK https://passport.yandex.ru/auth?retpath=https%3A%2F%2Foauth.yandex.ru%2Fauthorize%3Fresponse_type%3Dcode&origin=oauth (2196ms)
74 Server: nginx
75 Date: Sun, 27 Jan 2019 14:07:00 GMT
76 Content-Type: text/html; charset=utf-8
77 Transfer-Encoding: chunked
78 Connection: keep-alive
79 Keep-Alive: timeout=120
80D/OkHttp: Vary: Accept-Encoding
81 Content-Security-Policy: default-src 'none'; style-src 'self' yastatic.net 'unsafe-inline' 'unsafe-eval'; script-src 'self' yastatic.net mc.yandex.ru api-maps.yandex.ru suggest-maps.yandex.net export.yandex.ru 'unsafe-eval' 'unsafe-inline' 'nonce-897ee1c6-53db-44a3-87d7-62406bd0e77a'; img-src 'self' yastatic.net https://ysa-static.passport.yandex.net yandex.st data: mc.yandex.ru api-maps.yandex.ru *.captcha.yandex.net avatars.mds.yandex.net avatars.mdst.yandex.net clck.yandex.ru *.maps.yandex.net yapic.yandex.ru img.yandex.ru static-maps.yandex.ru https://video-tub-ru.yandex.net https://img0-tub-ru.yandex.net https://img1-tub-ru.yandex.net https://img2-tub-ru.yandex.net https://img3-tub-ru.yandex.net mc.webvisor.com mc.webvisor.org; font-src 'self' data: yastatic.net; object-src yastatic.net; media-src *.captcha.yandex.net data:; connect-src mail.yandex.ru 'self' mc.yandex.ru suggest-maps.yandex.net mc.webvisor.com mc.webvisor.org yandex.ru; frame-src 'self' yandex.st s4.money.yandex.net yandex.ru pass.yandex.ru passport.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; child-src 'self' yandex.st yandex.ru passport.yandex.ru pass.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; report-uri https://csp.yandex.net/csp?from=passport&yandex_login=&yandexuid=
82 X-Content-Security-Policy: default-src 'none'; style-src 'self' yastatic.net 'unsafe-inline' 'unsafe-eval'; script-src 'self' yastatic.net mc.yandex.ru api-maps.yandex.ru suggest-maps.yandex.net export.yandex.ru 'unsafe-eval' 'unsafe-inline' 'nonce-897ee1c6-53db-44a3-87d7-62406bd0e77a'; img-src 'self' yastatic.net https://ysa-static.passport.yandex.net yandex.st data: mc.yandex.ru api-maps.yandex.ru *.captcha.yandex.net avatars.mds.yandex.net avatars.mdst.yandex.net clck.yandex.ru *.maps.yandex.net yapic.yandex.ru img.yandex.ru static-maps.yandex.ru https://video-tub-ru.yandex.net https://img0-tub-ru.yandex.net https://img1-tub-ru.yandex.net https://img2-tub-ru.yandex.net https://img3-tub-ru.yandex.net mc.webvisor.com mc.webvisor.org; font-src 'self' data: yastatic.net; object-src yastatic.net; media-src *.captcha.yandex.net data:; connect-src mail.yandex.ru 'self' mc.yandex.ru suggest-maps.yandex.net mc.webvisor.com mc.webvisor.org yandex.ru; frame-src 'self' yandex.st s4.money.yandex.net yandex.ru pass.yandex.ru passport.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; child-src 'self' yandex.st yandex.ru passport.yandex.ru pass.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; report-uri https://csp.yandex.net/csp?from=passport&yandex_login=&yandexuid=
83 X-WebKit-CSP: default-src 'none'; style-src 'self' yastatic.net 'unsafe-inline' 'unsafe-eval'; script-src 'self' yastatic.net mc.yandex.ru api-maps.yandex.ru suggest-maps.yandex.net export.yandex.ru 'unsafe-eval' 'unsafe-inline' 'nonce-897ee1c6-53db-44a3-87d7-62406bd0e77a'; img-src 'self' yastatic.net https://ysa-static.passport.yandex.net yandex.st data: mc.yandex.ru api-maps.yandex.ru *.captcha.yandex.net avatars.mds.yandex.net avatars.mdst.yandex.net clck.yandex.ru *.maps.yandex.net yapic.yandex.ru img.yandex.ru static-maps.yandex.ru https://video-tub-ru.yandex.net https://img0-tub-ru.yandex.net https://img1-tub-ru.yandex.net https://img2-tub-ru.yandex.net https://img3-tub-ru.yandex.net mc.webvisor.com mc.webvisor.org; font-src 'self' data: yastatic.net; object-src yastatic.net; media-src *.captcha.yandex.net data:; connect-src mail.yandex.ru 'self' mc.yandex.ru suggest-maps.yandex.net mc.webvisor.com mc.webvisor.org yandex.ru; frame-src 'self' yandex.st s4.money.yandex.net yandex.ru pass.yandex.ru passport.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; child-src 'self' yandex.st yandex.ru passport.yandex.ru pass.yandex.ru https://trust.yandex.ru blob: mc.yandex.ru; report-uri https://csp.yandex.net/csp?from=passport&yandex_login=&yandexuid=
84 X-Frame-Options: DENY
85 X-Download-Options: noopen
86 X-Content-Type-Options: nosniff
87D/OkHttp: Surrogate-Control: no-store
88 Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate
89 Pragma: no-cache
90 Expires: 0
91 X-DNS-Prefetch-Control: off
92 X-XSS-Protection: 1; mode=block
93 P3P: policyref="/w3c/p3p.xml", CP="NON DSP ADM DEV PSD IVDo OUR IND STP PHY PRE NAV UNI"
94D/OkHttp: Set-Cookie: yandexuid=130802301548598020; Max-Age=315360000; Domain=.yandex.ru; Path=/; Expires=Wed, 24 Jan 2029 14:07:00 GMT
95 Set-Cookie: lah=; Domain=.passport.yandex.ru; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Secure; HttpOnly; Path=/
96 ETag: W/"6239-6EAmsUJd/dJRG//sq+aRLg"
97 Strict-Transport-Security: max-age=315360000; includeSubDomains; preload