#!/usr/bin/env perl
use warnings;
use strict;

use Net::OAuth2::Profile::WebServer;
use Net::VOOT::SURFnet;

use MIME::Base64;

use Data::Dumper;
$Data::Dumper::Indent   = 1;
$Data::Dumper::Sortkeys = 0;

# see https://frko.surfnetlabs.nl/workshop/
my %passwords =
  ( admin	=> 'adm1n'	# Carlos Catalano
  , teacher	=> 'teach3r'	# Margie Korn
  , jstroud	=> 'xDIosd9j'	# Jerry Stroud
  , mwisdom	=> 'LQ32xvaV'	# Myra Wisdom
  , bmcatee	=> 'ySVk4B9d'	# Bobby Mcatee
  , jmatson	=> '8r5yyIV3'	# Janie Matson
  , mcram	=> '62xX1Fid'	# Margaret Cram
  );

my %urn = 
  ( admin   => 'urn:x-oauth:entitlement:applications'
  , teacher => 'urn:x-oauth:entitlement:administration'
  );

@ARGV==1
    or die "Usage: $0 <username>\n";

my $username = shift;
my $password = $passwords{$username}
    or die "user $username does not exist. Pick from:\n  "
         . join(', ', sort keys %passwords) . "\n";

my $voot = Net::VOOT::SURFconext->new
  ( test          => 1
  , client_id     => 'sympa'
  , client_secret => 'apsym'
  , redirect_uri  => 'http://localhost/sympa'
  );

my $token = $voot->token;
warn Dumper $token;

my $token_info_url = $auth->site_url('php-oauth/tokeninfo.php');
my $api            = $auth->site_url('php-oauth/api.php');

# Implements the VOOT group interface
# https://frko.surfnetlabs.nl/workshop/voot-specification/VOOT.md

my $user  = undef;
my $group = undef;

warn Dumper $voot->userGroupInfo($user);
warn Dumper $voot->groupMemberInfo($group, $user);
warn Dumper $voot->userInfo($user);
