Ssibrahimbas Go-Auth
An authorization project using mongoDB, JWT and Go.
API
Types |
---|
User |
HTTP REQUEST | Name |
---|---|
POST |
Register |
POST |
Login |
GET |
Verify Login |
UserType
the user's fields and their types.
Field | Json | Bson | GoLang | Type |
---|---|---|---|---|
name |
name | name | Name | string |
gender |
gender | gender | Gender | string |
age |
age | age | Age | int |
email |
string | |||
password |
password | password | Password | string |
In Golang, starting fields with a capital letter makes them public. That's why the first letters of all our fields are capitalized. If we didn't want them to be accessible from outside (private), we would write them in lowercase.
register
If the user registers and the transaction is successful, a token is returned is the header of the Response.
Params | Type |
---|---|
name |
string |
gender |
string |
age |
int |
email |
string |
password |
string |
Example Request
POST http://localhost:8080/api/register
Content-Type: application/json
{
"name": "Sami Salih İbrahimbaş",
"gender": "Man",
"age": 20,
"email": "[email protected]",
"password": "secretPassword"
}
Returns
{
"success": true,
"message": "Login Successful."
}
login
The user enters the email and password fields. If there is a registration and the passwords match, the login is provided. In the header of Response, the token is passed as in the registration process.
Params | Type |
---|---|
email |
string |
password |
string |
Example Request
POST http://localhost:8080/api/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "secretPassword"
}
Returns
{
"success": true,
"message": "Login Successful."
}
verifyLogin
Token is sent in Request's Header. If the token exists and is available, the entry is validated. Otherwise, an error is received.
Example Request
GET http://localhost:8080/api/verifyLogin
Authorization: Bearer dssdcvkşldscasşasdşlsadlşef
Returns
{
"success": false,
"message": "Not Authorized"
}