Add filters to authentication flow to allow external authentication#129
Add filters to authentication flow to allow external authentication#129acafourek wants to merge 1 commit intowp-graphql:developfrom
Conversation
Adds two filters: `graphql_jwt_auth_use_wp_authentication` -- returns boolean to determine if should use WP authentication `graphql_jwt_auth_authenticate_user` -- returns authenticated user or WP_Error Also passes full query input along to Auth functions and filters to give SSO provider access to data
|
Hi @acafourek, Would you have a working example of how this would work on a front end app. For example, how would I run this after I get a response from Google's SSO? Any info you have would be greatly appreciated. |
My code here assumes you have some supporting WP plugin applying filters to the WPGraphql JWT plugin that intercepts the authentication flow, interprets data from the front end and tells the plugin if your extra level of authentication has been successful. So your FE app would only be involved so far as it's making the GQL query to But you could certainly use the approach described above to support some Google SSO authentication flow, but you'd need to write your own WP Plugin to communicate with Google inside the filters I outline in the example. |
Adds two filters:
graphql_jwt_auth_use_wp_authentication-- returns boolean to determine if should use WP authenticationgraphql_jwt_auth_authenticate_user-- returns authenticated user or WP_ErrorAlso passes full query input along to Auth functions and filters to give SSO provider access to data. The modifications to the JWT plugin are fairly minimal and maintain backward compatibility.
We've been using this modification in order to support an SSO integration where users are linked to an external site to login and we determine authentication based on the validation of a code they return with.
I thought this might be useful to others, so I've made the changes to the core plugin as minimal as possible and you can also see below how we've implemented them in our own code. Using these new filters, we've written some code in our own plugin that adds some parameters to the
loginUsermutation where we pass SSO information, then tap that outside service for authentication.So then our
loginUsermutation looks like this:{ "username": "testUser@testemail.com", "password": "p@ssword", "sso": { "provider": "MyCustomSSOProvider", "auth": "f962681c-89a8-49dd-ba51-8s5f5e91243" } }