Jump to content

OAuth 2 WordPress plugin


Recommended Posts

Basically you can map anything into WordPress from what Vatsim gives you:
The CID is used as unique WordPress username, then you have some 'metadata' which is firstname and lastname. Maybe you need some plugins to show Fullname/lastname instead of Username in Posts/Forum etc, but that's secondary.

Return Array:
Array (
[data] => Array ( [cid] => 859396
[personal] => Array ( [name_first] => Jamie [name_last] => Janssen [name_full] => Jamie Janssen [email] => [email protected]
[country] => Array ( [id] => NL [name] => Netherlands ) )
[vatsim] => Array ( [rating] => Array ( [id] => 2 [long] => Tower Trainee [short] => S1 )
[pilotrating] => Array ( [id] => 0 )
[division] => Array ( [id] => EUD [name] => Europe (except UK) )
[region] => Array ( [id] => EUR [name] => Europe )
[subdivision] => Array ( [id] => NETH [name] => Dutch ) )
[oauth] => Array ( [token_valid] => true ) ) )

I hid my email adres ūüėȬ†But this is what you get. We feed this into WP and use WP_roles to assign a specific role (permission) to a user. This can be done using the Wordpress functions. Actually quite easy, for example:¬†https://developer.wordpress.org/reference/functions/wp_create_user/¬†to create the user.

So in short:
- we have a separate member role plugin to assign roles to a specific user (vatsim member, dutchvacc member, ATC, etc)
- we assign the roles upon login by checking the Array above: is the user's devision NETH? -> we assign DV Member.

The rest is done via the normal WordPress backend: permissions according the assigned roles to specific parts of the site. Works like a charm!

Edit: try to stick to the WordPress database specs. We did not 'hack' extra fields into the wp_user database for example. This to keep everything according WP standards and this keeps WP (hopefully) future proof.

Edited by Jamie Janssen
  • Like 1

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

 
 
 
  webmaster@dutchvacc.nl
  https://www.dutchvacc.nl
1867669885_DVLogo.thumb.jpg.3f12623d8d3006d2e0ec97a8469dab4b.jpg
Link to post
Share on other sites
3 hours ago, Jamie Janssen said:

Basically you can map anything into WordPress from what Vatsim gives you:
The CID is used as unique WordPress username, then you have some 'metadata' which is firstname and lastname. Maybe you need some plugins to show Fullname/lastname instead of Username in Posts/Forum etc, but that's secondary.

Return Array:
Array (
[data] => Array ( [cid] => 859396
[personal] => Array ( [name_first] => Jamie [name_last] => Janssen [name_full] => Jamie Janssen [email] => [email protected]
[country] => Array ( [id] => NL [name] => Netherlands ) )
[vatsim] => Array ( [rating] => Array ( [id] => 2 [long] => Tower Trainee [short] => S1 )
[pilotrating] => Array ( [id] => 0 )
[division] => Array ( [id] => EUD [name] => Europe (except UK) )
[region] => Array ( [id] => EUR [name] => Europe )
[subdivision] => Array ( [id] => NETH [name] => Dutch ) )
[oauth] => Array ( [token_valid] => true ) ) )

I hid my email adres ūüėȬ†But this is what you get. We feed this into WP and use WP_roles to assign a specific role (permission) to a user. This can be done using the Wordpress functions. Actually quite easy, for example:¬†https://developer.wordpress.org/reference/functions/wp_create_user/¬†to create the user.

So in short:
- we have a separate member role plugin to assign roles to a specific user (vatsim member, dutchvacc member, ATC, etc)
- we assign the roles upon login by checking the Array above: is the user's devision NETH? -> we assign DV Member.

The rest is done via the normal WordPress backend: permissions according the assigned roles to specific parts of the site. Works like a charm!

Edit: try to stick to the WordPress database specs. We did not 'hack' extra fields into the wp_user database for example. This to keep everything according WP standards and this keeps WP (hopefully) future proof.

Thank you so much for the very detailed explanation!!

Link to post
Share on other sites
  • 2 months later...

Hi there,

 

We are looking to integrate VATSIM Connect with our ARTCC website. It's powered by WP 5.6.1, and right now we have to manually create accounts for new controllers (home or visiting). Jamie, can you please get in touch with me privately by email (tyler.rodick (at) zlcartcc (dot) com) with info on how to set up this plugin as well as download details? Thanks.

 

Tyler Rodick, VATUSA ZLC ARTCC Assistant Webmaster

Tyler Rodick, AWM

VATUSA

ZLC ARTCC

Link to post
Share on other sites

Hi all!

I just found a few spare minutes to¬†drop the bomb here ūüôā

The (currently unofficial) WorPress Vatsim Connect Plugin brought to you by the Dutch VACC.
https://gitlab.com/jamiejanssen/wp-plugin-vatsim-connect-public

We customized it heavily to our Dutch VACC's needs, so I had to clean quite a bit of the code to make things work for all VACCs. The code is small and clean. I guess quite readable as well. Feel free to comment/change and alter to your needs. Any questions? Just ask!

I HIGHLY recommend you to try this on a test-site first!

P.s. I'm not a professional programmer, I'm an airline captain. ENJOY!

Edited by Jamie Janssen
  • Like 1
  • Thanks 2

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

 
 
 
  webmaster@dutchvacc.nl
  https://www.dutchvacc.nl
1867669885_DVLogo.thumb.jpg.3f12623d8d3006d2e0ec97a8469dab4b.jpg
Link to post
Share on other sites
  • 4 weeks later...

Hi.  I'm the ATM at Salt Lake City ARTCC in VATUSA (ZLC).  Tyler Rodick, who posted above, it working with us.  We got the plugin installed and it will create/verify an account on our website via SSO, but you cannot tell if you are signed in or not?  I don't know if SSO isn't working right or if we somehow need to adjust permissions for the roles we need to have?  I'm not a coder at all.  I don't even really understand what an API is.  I did build the site in WordPress and it is the latest version of WP, but that's about all I know.  I'm happy to invite someone into our Discord and share my screen and they can help me get through everything to verify if it's working correctly?  If we turn debugging on we get an error during the SSO procedure.

PHP Notice: Undefined variable: redirectURL in /home/u402264082/domains/zlcartcc.com/public_html/wp-content/plugins/vatsim-connect/vatsim_connect.php on line 104

So I don't know what's going on?  Any help would be appreciated.

Thanks

Paul Biderman

Link to post
Share on other sites
On 3/17/2021 at 5:38 PM, Paul Biderman said:

Hi.  I'm the ATM at Salt Lake City ARTCC in VATUSA (ZLC).  Tyler Rodick, who posted above, it working with us.  We got the plugin installed and it will create/verify an account on our website via SSO, but you cannot tell if you are signed in or not?  I don't know if SSO isn't working right or if we somehow need to adjust permissions for the roles we need to have?  I'm not a coder at all.  I don't even really understand what an API is.  I did build the site in WordPress and it is the latest version of WP, but that's about all I know.  I'm happy to invite someone into our Discord and share my screen and they can help me get through everything to verify if it's working correctly?  If we turn debugging on we get an error during the SSO procedure.

PHP Notice: Undefined variable: redirectURL in /home/u402264082/domains/zlcartcc.com/public_html/wp-content/plugins/vatsim-connect/vatsim_connect.php on line 104

So I don't know what's going on?  Any help would be appreciated.

Thanks

change in vatsim_connect.php on line 104 from 

vc_validate($vat_cid, $vat_email, $vat_name_first, $vat_name_last, 
                        $vat_subdiv, $vat_dvm, $vat_oauth_token, $redirectURL); 

to

vc_validate($vat_cid, $vat_email, $vat_name_first, $vat_name_last, 
						$vat_subdiv, $vat_dvm, $vat_oauth_token, $appRedirectURL); 

$appRedirectUrl variable should be defined in config.php file

Call me clear of weather!

ACCRO2 - ROvACC Deputy DIrector

Link to post
Share on other sites


Sorry guys I'm quite busy at the moment, not always near the internet. There are probably some left-overs from the Dutch VACC. We differentiate Vatsim members from Dutch VACC members. I removed that part from the plugin as it needs extra WP plugins (Member roles).

I will look into it today.

Edit: This definately needs cleanup, the validate only needs $vat_cid, so I will remove the leftovers and run a¬†testūüėČ

vc_validate($vat_cid, $vat_email, $vat_name_first, $vat_name_last, 
						$vat_subdiv, $vat_dvm, $vat_oauth_token, $appRedirectURL);
Edited by Jamie Janssen

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

 
 
 
  webmaster@dutchvacc.nl
  https://www.dutchvacc.nl
1867669885_DVLogo.thumb.jpg.3f12623d8d3006d2e0ec97a8469dab4b.jpg
Link to post
Share on other sites

Hi @Paul Biderman,

I pushed a new update to¬†GitLab. Removed some left-overs, so you won't see¬†the Php Notice anymore ūüôā
Don't forget to backup your config.php before uploading the new version!

https://gitlab.com/jamiejanssen/wp-plugin-vatsim-connect-public

Edited by Jamie Janssen

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

 
 
 
  webmaster@dutchvacc.nl
  https://www.dutchvacc.nl
1867669885_DVLogo.thumb.jpg.3f12623d8d3006d2e0ec97a8469dab4b.jpg
Link to post
Share on other sites

Thanks for the update.  It still doesn't work for us and I don't understand why?  Everything seems to be configured correctly.  If you don't have a cookie set in your browser, or it's the first time you're logging in, it goes to the VATSIM SSO page and acts like it logs in.  But when it redirects back to our page nothing has changed.  If it's your first time logging in, it creates an account in WordPress with your VATSIM CID as the username, so that part is working at least.  But my users with admin access (such as myself if I use the SSO account) don't have admin access.  The menus that are hidden from the public are still hidden.  I have a "VATSIM SSO" custom link to login, that's supposed to only be visible if you're not logged in, and it's always visible.  I have a "Logout" custom link that's supposed to only be visible to logged in users.  It's never visible.  So I'm at a loss.  We're using a combination of the following plugins to try to manage access:

User Role Editor

Ultimate Member

Advanced Access Manager

If anyone has any ideas we'd really appreciate the help.  I'm happy to invite you to our discord and work through it together.  We just really need to get this working if possible.

Edited by Paul Biderman

Paul Biderman

Link to post
Share on other sites

Something that is easily overlooked: the website's URL. Especially when using www or no www (or redirect www to non-www).

Please make sure the URLs in:
Settings -> General -> WordPress Address (URL)
and
Settings -> General -> Site Address (URL)
matches the $appRedirectURL in the config.php and the URL you have setup in https://auth.vatsim.net/ -> OAuth -> 2.0 clients.

For example:

https://thisvacc.com  is not the same thing as https://www.thisvacc.com

if your website is https://thisvacc.com and you have setup the OAuth2 plugin to redirect to https://www.thisvacc.com it will not work!

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

 
 
 
  webmaster@dutchvacc.nl
  https://www.dutchvacc.nl
1867669885_DVLogo.thumb.jpg.3f12623d8d3006d2e0ec97a8469dab4b.jpg
Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...