How to implement login and login maintenance on Android when using REST API

Asked 2 years ago, Updated 2 years ago, 82 views

Hello.

I am a very beginner in programming.

I've worked on REST api through Django (django-rest-auth), but I have no idea how to implement login here, so I'm posting a question here.

The api I made is json type

{
    "username": "",
    "email": "",
    "password1": "",
    "password2": ""
}

After sending the in a post manner

HTTP 200 OK
  Allow: POST, OPTIONS
  Content-Type: application/json
  Vary: Accept

  {
    "key": "99defb355414133f00ad88e15771e3a8b43e71f"
}

In this way, the key value is received in json type. I don't know why they give me this key.

Does giving this key value mean basic authentication?

    "description": "Check the credentials and return the REST Token\nif the credentials are valid and authenticated.\nCalls Django Auth login method to register User ID\nin Django session framework\n\nAccept the following POST parameters: username, password\nReturn the REST Framework Token Object's key.",

I'm asking because I don't even know what I should study with just this explanation.

I don't know which part to study or how to implement it.

I'd appreciate it if you let me know.

I heard retrofit is good, so I want to apply it here, but I don't know what to do.

I don't know how to log in or maintain it, so I'd appreciate it if you could give me a little hint.

android django rest

2022-09-22 21:56

1 Answers

Token (any string) dropped by the server after login "key": "99defb355414133f00ad88e15771e3a8b43e71f" is required to request an API.

Briefly explain the flow

You asked me about how to keep my login, and if the token issued by the server is valid, I can understand that my login is maintained. If you haven't been using the app for a long time and want to log in again when the app is restarted, the server can expire the token, drop the promised error code to the client, and then display the login screen on the client.)

Retrofit has a variety of easy-to-learn examples. I think you'll be able to feel the charm if you follow the code. Please refer to the articles below.


2022-09-22 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.