Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String url = LoginConstants.URL_OAUTH;
- HttpClient client = HttpClientBuilder.create().build();
- HttpPost post = new HttpPost(url);
- post.addHeader(HttpHeaders.AUTHORIZATION, LoginConstants.BASIC_AUTHORIZATION);
- post.addHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
- List<NameValuePair> body = new ArrayList<NameValuePair>();
- body.add(new BasicNameValuePair(LoginConstants.GRANT_TYPE, LoginConstants.GRANT_TYPE_VALUE));
- body.add(new BasicNameValuePair(LoginConstants.USER_NAME, user));
- body.add(new BasicNameValuePair(LoginConstants.PASSWORD, password));
- body.add(new BasicNameValuePair(LoginConstants.SCOPE, LoginConstants.SCOPE_VALUE));
- UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, CharEncoding.UTF_8);
- post.setEntity(entity);
- HttpResponse response = client.execute(post);
- OkHttpClient client = new OkHttpClient();
- MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
- RequestBody body = RequestBody.create(mediaType, "grant_type=password&username=canido&password=canido08&scope=customScope");
- Request request = new Request.Builder()
- .url("https://localhost:7001/OAuth/token")
- .post(body)
- .addHeader("authorization", "Basic XXX")
- .addHeader("content-type", "application/x-www-form-urlencoded")
- .addHeader("cache-control", "no-cache")
- .addHeader("postman-token", "b81569ff-5f3f-f009-d512-ef4258808e01")
- .build();
- Response response = client.newCall(request).execute();
Add Comment
Please, Sign In to add comment