Jump to content

You're browsing the 2004-2023 VATSIM Forums archive. All content is preserved in a read-only fashion.
For the latest forum posts, please visit https://forum.vatsim.net.

Need to find something? Use the Google search below.
PLEASE READ - Webmaster Support Forum
This forum will be retired in the near future. Please direct all queries to our dedicated GitHub support page https://github.com/vatsimnetwork/developer-info/discussions 
Here you can find documentation on our services and we are continuing to migrate pertinent information into the Wiki pages https://github.com/vatsimnetwork/developer-info/wiki

OAuth 2 WordPress plugin


Martijn Rammeloo
 Share

Recommended Posts

Jamie Janssen
Posted
Posted (edited)

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 comment
Share on other sites

Jamie Janssen
Posted
Posted
15 hours ago, Nestor Perez said:

Hey Jamie, could you join the Dev Discord announced in the latest Tech Blog post and reach out to us through there, please?

I'll try to find it 🙂 

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

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

Joseph Pentz
Posted
Posted
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 comment
Share on other sites

Jamie Janssen
Posted
Posted

Update on the WordPress Vatsim Connect plugin:

- I removed all Dutch VACC code.
- Gave Joseph Pentz a test-version, seems to work.
- Basically ready to be released into the wild.

  • Like 1

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

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

  • 2 months later...
Steven Fauconnier
Posted
Posted

Is this already out in the wild?

Belux vACC Director (ACCBE1)|Mail: steven.fauconnier(at)beluxvacc.org

------------------

ATSimTest Lead - VATSIM Europe Division |Mail: steven.fauconnier(at)vateud.net

Link to comment
Share on other sites

Jamie Janssen
Posted
Posted

No, but I’m happy to share it with the community.

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

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

Steven Fauconnier
Posted
Posted

Great! Can you send our tech dept all relevant info to implement the new Connect in Wordpress? [email protected].

Thx

Belux vACC Director (ACCBE1)|Mail: steven.fauconnier(at)beluxvacc.org

------------------

ATSimTest Lead - VATSIM Europe Division |Mail: steven.fauconnier(at)vateud.net

Link to comment
Share on other sites

Dean Roy
Posted
Posted
On 2/8/2021 at 5:28 AM, Steven Fauconnier said:

Great! Can you send our tech dept all relevant info to implement the new Connect in Wordpress? [email protected].

Thx

I would also like to get access to this if it is available?

Could you send to [email protected]  ?

 

Link to comment
Share on other sites

Tyler Rodick
Posted
Posted

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 comment
Share on other sites

Jamie Janssen
Posted
Posted (edited)

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 comment
Share on other sites

  • 4 weeks later...
Paul Biderman
Posted
Posted

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
ZAN DATM

Link to comment
Share on other sites

George Enciu
Posted
Posted
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 comment
Share on other sites

Jamie Janssen
Posted
Posted (edited)


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 comment
Share on other sites

Jamie Janssen
Posted
Posted (edited)

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 comment
Share on other sites

Paul Biderman
Posted
Posted (edited)

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
ZAN DATM

Link to comment
Share on other sites

Jamie Janssen
Posted
Posted

Happy to help you. Just write me a pm or contact me at discord: Jamie#7212 (be aware: case sensitive!)

Jamie Janssen

ACCNL3 Webmaster

Dutch VACC

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

Paul Biderman
Posted
Posted

Thanks Jamie.  I just sent you a friend request on Discord.

Paul Biderman
ZAN DATM

Link to comment
Share on other sites

Jamie Janssen
Posted
Posted

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 comment
Share on other sites

Paul Biderman
Posted
Posted

Thank you very much for the help Jamie!

  • Like 1

Paul Biderman
ZAN DATM

Link to comment
Share on other sites

 Share