Guest User

Untitled

a guest
Jun 14th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. **My Post Data**
  2.  
  3.  
  4. {
  5. "auth": {
  6. "identity": {
  7. "methods": [
  8. "password"
  9. ],
  10. "password": {
  11. "user": {
  12. "id": "bbe57ffd805346f88930466fcf7cbe0d",
  13. "password": "6790"
  14. }
  15. }
  16. },
  17. "scope": {
  18. "project": {
  19. "id": "76b6432f3ea649e3acdd9fd91643ef05"
  20. }
  21. }
  22. }
  23. }
  24.  
  25. package com.example.server.restapi.api.model;
  26.  
  27. import com.google.gson.annotations.Expose;
  28. import com.google.gson.annotations.SerializedName;
  29.  
  30. public class Auth {
  31.  
  32. @SerializedName("identity")
  33. @Expose
  34. private Identity identity;
  35. @SerializedName("scope")
  36. @Expose
  37. private Scope scope;
  38.  
  39. public Identity getIdentity() {
  40. return identity;
  41. }
  42.  
  43. public void setIdentity(Identity identity) {
  44. this.identity = identity;
  45. }
  46.  
  47. public Scope getScope() {
  48. return scope;
  49. }
  50.  
  51. public void setScope(Scope scope) {
  52. this.scope = scope;
  53. }
  54.  
  55. }
  56.  
  57. package com.example.server.restapi.api.model;
  58.  
  59. import com.google.gson.annotations.Expose;
  60. import com.google.gson.annotations.SerializedName;
  61.  
  62. public class Example {
  63.  
  64. @SerializedName("auth")
  65. @Expose
  66. private Auth auth;
  67.  
  68. public Auth getAuth() {
  69. return auth;
  70. }
  71.  
  72. public void setAuth(Auth auth) {
  73. this.auth = auth;
  74. }
  75.  
  76. }
  77.  
  78. package com.example.server.restapi.api.model;
  79.  
  80. import java.util.List;
  81. import com.google.gson.annotations.Expose;
  82. import com.google.gson.annotations.SerializedName;
  83.  
  84. public class Identity {
  85.  
  86. @SerializedName("methods")
  87. @Expose
  88. private List<String> methods = null;
  89. @SerializedName("password")
  90. @Expose
  91. private Password password;
  92.  
  93. public List<String> getMethods() {
  94. return methods;
  95. }
  96.  
  97. public void setMethods(List<String> methods) {
  98. this.methods = methods;
  99. }
  100.  
  101. public Password getPassword() {
  102. return password;
  103. }
  104.  
  105. public void setPassword(Password password) {
  106. this.password = password;
  107. }
  108.  
  109. }
  110.  
  111. package com.example.server.restapi.api.model;
  112.  
  113. import com.google.gson.annotations.Expose;
  114. import com.google.gson.annotations.SerializedName;
  115.  
  116. public class Password {
  117.  
  118. @SerializedName("user")
  119. @Expose
  120. private User user;
  121.  
  122. public User getUser() {
  123. return user;
  124. }
  125.  
  126. public void setUser(User user) {
  127. this.user = user;
  128. }
  129.  
  130. }
  131.  
  132. package com.example.server.restapi.api.model;
  133.  
  134. import com.google.gson.annotations.Expose;
  135. import com.google.gson.annotations.SerializedName;
  136.  
  137. public class Project {
  138.  
  139. @SerializedName("id")
  140. @Expose
  141. private String id;
  142.  
  143. public String getId() {
  144. return id;
  145. }
  146.  
  147. public void setId(String id) {
  148. this.id = id;
  149. }
  150.  
  151. }
  152.  
  153. package com.example.server.restapi.api.model;
  154.  
  155. import com.google.gson.annotations.Expose;
  156. import com.google.gson.annotations.SerializedName;
  157.  
  158. public class Scope {
  159.  
  160. @SerializedName("project")
  161. @Expose
  162. private Project project;
  163.  
  164. public Project getProject() {
  165. return project;
  166. }
  167.  
  168. public void setProject(Project project) {
  169. this.project = project;
  170. }
  171.  
  172. }
  173.  
  174. package com.example.server.restapi.api.model;
  175.  
  176. import com.google.gson.annotations.Expose;
  177. import com.google.gson.annotations.SerializedName;
  178.  
  179. public class User {
  180.  
  181. @SerializedName("id")
  182. @Expose
  183. private String id;
  184. @SerializedName("password")
  185. @Expose
  186. private String password;
  187.  
  188. public String getId() {
  189. return id;
  190. }
  191.  
  192. public void setId(String id) {
  193. this.id = id;
  194. }
  195.  
  196. public String getPassword() {
  197. return password;
  198. }
  199.  
  200. public void setPassword(String password) {
  201. this.password = password;
  202. }
  203.  
  204. }
  205.  
  206. package com.example.server.restapi;
  207.  
  208. import android.support.v7.app.AppCompatActivity;
  209. import android.os.Bundle;
  210. import android.widget.TextView;
  211. import android.widget.Toast;
  212.  
  213. import com.example.server.restapi.api.model.Auth;
  214. import com.example.server.restapi.api.model.Identity;
  215. import com.example.server.restapi.api.model.Project;
  216. import com.example.server.restapi.api.model.Scope;
  217. import com.example.server.restapi.api.model.User;
  218. import com.example.server.restapi.api.model.service.UserClient;
  219.  
  220. import java.util.ArrayList;
  221. import java.util.List;
  222.  
  223. import okhttp3.Headers;
  224. import okhttp3.ResponseBody;
  225. import retrofit2.Call;
  226. import retrofit2.Callback;
  227. import retrofit2.Response;
  228. import retrofit2.Retrofit;
  229. import retrofit2.converter.gson.GsonConverterFactory;
  230.  
  231. public class MainActivity extends AppCompatActivity {
  232. public static String token;
  233. TextView textView;
  234.  
  235.  
  236.  
  237.  
  238. Retrofit.Builder builder = new Retrofit.Builder().baseUrl("http://192.168.0.106:5000/v3/auth/").
  239. addConverterFactory(GsonConverterFactory.create());
  240.  
  241. Retrofit retrofit = builder.build();
  242. UserClient userClient = retrofit.create(UserClient.class);
  243.  
  244. @Override
  245. protected void onCreate(Bundle savedInstanceState) {
  246. super.onCreate(savedInstanceState);
  247. setContentView(R.layout.activity_main);
  248. textView= findViewById(R.id.textView);
  249. List<String> methods = new ArrayList<String>();
  250. methods.add("password");
  251. Identity identity = new Identity();
  252. identity.setMethods(methods);
  253. User user = new User();
  254. user.setPassword("6790");
  255. user.setId("bbe57ffd805346f88930466fcf7cbe0d");
  256. Project project = new Project();
  257. project.setId("76b6432f3ea649e3acdd9fd91643ef05");
  258.  
  259. login();
  260.  
  261.  
  262.  
  263.  
  264. }
  265.  
  266. public void login()
  267. {
  268.  
  269. Auth auth = new Auth();
  270. Call<ResponseBody> call= userClient.login(auth);
  271.  
  272.  
  273. call.enqueue(new Callback<ResponseBody>() {
  274. @Override
  275. public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
  276.  
  277. Headers headers = response.headers();
  278.  
  279. token = response.headers().get("x-subject-token");
  280. textView.setText(token);}
  281.  
  282. @Override
  283. public void onFailure(Call<ResponseBody> call, Throwable t) {
  284.  
  285. Toast.makeText(MainActivity.this, "error", Toast.LENGTH_SHORT).show();
  286.  
  287. }
  288. });
  289.  
  290.  
  291.  
  292.  
  293. }
  294. }
Add Comment
Please, Sign In to add comment