laravel jwtAuth validate credentials - mysql

I'm developing API in laravel and trying to implement token base auth with jwtAuth but what I cannot understand is that how to use mysql table 'customers' for authentication and generate token.
I have gone through multiple tutorials but none of them explain mysql table for authentication .
Does mysql really required for jwtAuth ?
How to manage jwtAuth::attempt() function for mysql ?
What is default table for jwtAuth() ?
Some of the tutorial that I have followed are : this and this

JWT authentication is an extension of the base Authentication, and uses the same configuration and methods as defined in your config/auth.php file.
User data will be stored in the defined users table - if using the standard Authentication scaffolding this is just users.
The JWT sessions themselves will be stored based on your session configuration. By default this uses file based session, stored within the
folder storage/framework/sessions

Related

React: Store <Form> data from to MySQL

I have created a register page in reactjs, where I am taking firstName, lastName, password, email from a user.
In the backend, I have created the application using SpringBoot to handle the request from frontend.
Now, I am able to store (temporarily) the register form data in http://localhost:8080/forms .
When the user enters the data in register form at the front end, the data is stored temporarily in the spring boot application in the url mentioned in the axios.
So, when I enter this url (in the browser), am able to see the list of registered users with their credentials in JSON format like this :
[{"firstName":"Bhavya", "lastName":"Gupta", "email":"abcd#a", "password":"zaqxsw","id":100}]
But this data is temporarily stored, so when I restart the server the data is no longer there.
submitBook= event =>{
event.preventDefault();
const book = {
firstName: this.state.firstName,
lastName: this.state.lastName,
password: this.state.password,
email: this.state.email
};
axios.post("http://localhost:8080/forms",book).then(response => {
if(response.data!=null){
this.setState({"show":true});
setTimeout(() => this.setState({"show":false}),3000);
} else {
this.setState({"show":false});
}
});
this.setState(this.initialState);
}
The complete code is available here
I want to store the register form data from front-end (client-side) into a MySQL database, so that I can perform login authentication on the data stored.
I have created MySQL database with 4 columns - firstName, lastName, email, password. I searched on the internet and read several answers in SO Sending data to database in React, referred several blogs and articles, but I am not able to understand how to achieve this.
Can anyone please help me out in solving this issue?
In a typical/modern web application, you have well defined roles/purposes for each part of the system. From your question, it appears that you intend for the roles to be interchanged and that might the source of your troubles here.
Let;s look closely at your set-up:
Client-side/Front-end (JavaScript/React)
This is simply an enabler for a user to interact with your actual application. In your set-up, this should render the form and capture registration data.
Server-side/Back-end (Java/SpringBoot)
This is your application layer where most processing happens (business logic).
In your set-up, this is where your MVC happens. And essentially, after any required validation, this layer then communicates with the Database.
Database-layer (SQL or NoSQL)
This is the layer that you utilize to store and persist data within your app. In your set-up, you are using MySQL to handle your data.
Already your backend is already exposing endpoints which you are consuming at the front-end via axios. Therefore the direct answer to your question lies in getting SpringBoot to work with your MySQL in order to persist your data.
Here is an official tutorial on how to access data with MySQL from the spring team.
For Posting Form data from ReactJS to MySQL database via Spring Boot Application, I have written blogs, that gives a detailed explanation and a step by step method to connect front end part with backend .
Refer to these blogs :
Prerequisites to POST form data from ReactJS to an API endpoint : Part 1
Initial Setup for creating a basic React App: Part 2
Posting Form data from ReactJS to MySQL database via Spring Boot Application: Part 3

Adding a mysql user store with custom schema to WSO2 Identity Server

Currently, trying to use WSO2 Identity Server to authenticate users from a mysql user store that I created with my own schema. However, whenever I add this user store as a secondary one in WSO2, the users do not appear on the management console.
And when I attempt to authenticate a user from that store I get the error message:
[2019-05-24 10:01:15,951] ERROR{org.wso2.carbon.identity.auth.service.handler.impl.BasicAuthenticationHandler}
- Error occurred while trying to authenticate,
Error when handling event : PRE_AUTHENTICATION
The user stores of the WSO2 servers need to have the specific schema (the schema script located in the dbscripts folder). You need to import users using this from your existing schema or scim2 endpoints to programmably import users
I you cannot migrate user store to wso2 schema as senthalan explained then you have two options to plug custom schema.
Change SQL queries from Advanced option of secondary user store configuration
Writing custom user store manager by extending necessary functions like doAuthenticate, doAddUser [1]
Error when handling event : PRE_AUTHENTICATION basically coming from below listener
org.wso2.carbon.identity.governance.listener.IdentityMgtEventListener in identity.xml while handling pre authenticate event. You can even disable it.
[1]https://github.com/GayanM/custom-user-store

CAS LDAP and database query

I have a user authenticated against LDAP using CAS. I now have the UID. Is it possible to use CAS to also query an oracle database using the UID to get other user attributes stored from oracle?
I've tried to use SingleRowJdbcPersonAttributeDao class in my bean but I can't get any attributes to release from it ... I'm not even sure if the query is being executed.
Yes. authentication in CAS is different from attribute retrieval. You can authenticate via one source, and get attributes from another. Authentication is handled via authN handlers, and attribute retrieval is handled via attribute repositories.
Once you have retrieved attributes, you need to configure your service definition to release those attributes. You need to define an attribute policy that authorizes the release of all or select attributes.
See http://jasig.github.io/cas/4.1.x/integration/Attribute-Release.html

json login on spring security

I'm building a REST back end based on spring and i'm using spring security to secure the requests. But i'm lookin for an issue to login by sending parameters in json rather than defaults parameters sent by the default login page of spring security.
I'm working with spring security 4.0.1 and spring 4.1
Any issue please?
If you're using just username and password, you can simply add a new filter to the stack, akin to the existing UsernamePasswordAuthenticationFilter, that would react to a specific URL only (just like the default one reacts to j_spring_security_check only), parse the JSON and create the very same UsernamePasswordAuthenticationToken that the default filter creates. This leaves the auth provider the same as the token didn't change.
If you need more fields in addition to username and password, either create a new token type (or use existing one if it makes sense) and a new auth provider that can deal with that token type. You can also just cram extra fields into UsernamePasswordAuthenticationToken using setDetails(), but this is a bit hacky.

How to control access to HTML pages in Tomcat 5.5 using tokens

I have a Tomcat 5.5 server that hosts some HTML pages. I want to control the access to these pages. The incoming users' HTTP requests are supposed to have special authentication values.
What I need is to write a function that returns true/false based on the authentication value for each user request. Based on this true/false value, the user should be granted the access or not.
Any idea about how to do that?
Thanks
A pragmatic solution would be to create a ServletFilter and map it to all resources (/*). Reading your question, I guess your authentication method will not be based on sessions (JSESSIONID cookie), but on tokens part of the URL itself.
You have to write your own Authenticator in Tomcat.
Edit:
Subclass the AuthencatorBase class and implement the the abstract method authenticate
Place your jar in the lib folder of tomcat, not your webapp
specify in your web.xml which resources your want to protect.
Declare your authenticator in your context.xml => this technically a Valve
deploy your application and be happy!
With Tomcat, you'll need to use a Realm to protect your pages.
http://tomcat.apache.org/tomcat-4.1-doc/realm-howto.html