Michael Dondrup
2015-01-30 14:01:05 UTC
Hi Lishuang,
could you have a look at:
https://github.com/mdondrup/GBrowse/blob/master/cgi-bin/samlPostEpr
and tell me if that helps you. The interaction with the gbrowse api starts at line 45.
To avoid a having to rewrite and use the gbrowse main cgi as
a receiver for the POST message I added another endpoint script. Apart from receiving and
validating the encrypted SAML code it also contains the logic to create a gbrowse user and
session and to initialize the session and to 'redirect' via java script. Note that we trust the
SAML authentication in that we will also create a new gbrowse user in the database if there
is not already such an account.
Please let me know if you have any further questions.
Best
Michael
Michael Dondrup
Postdoctoral fellow
Sea Lice Research Centre/Department of Informatics
University of Bergen
Thormøhlensgate 55, N-5008 Bergen,
Norway
On Jan 30, 2015, at 2:35 PM, Lishuang Shen wrote:
> Hello:
>
> Regarding your 3rd party logon. I need your advice.
>
> http://sourceforge.net/p/gmod/mailman/message/33295297/
>
>
>
> I am following similar strategyto yours above for 3rd party login done with PHP. I handled
> the information with perl PHP::session and able to read and validate the PHP generated
> session and validated with session information in Gbrowse mysql.
>
> I use database to store the user and session information, not using files.
> So I am trying to activate my validated session information into Gbrowse.
> But stuck here regarding how to set cookie. It will jump to the gbrowse page, but not able to logon.
>
>
>
>
> Thank you,
>
> Lishuang
>
>
>
>
> #########################################################
> # I am trying to use directly the part of gbrowse login, for some infoirmation:
>
> my $nonce = Bio::Graphics::Browser2::Util->generate_id;
> my $ip = CGI::remote_addr(); ## OK for ssl?
> $session-> set_nonce($nonce,$ip, 1); #set_nonce($nonce,$ip,$remember);
> $session-> using_openid('false');
> my $uploadsid = $userdb-> get_uploads_id($userid);
>
> print STDERR "id= $sessionid_from_user, IP: $ip $nonce -- username =", $session->username;
> print STDERR "\nauthorize_user: $userid, $sessionid_from_user ". $session->id . " 2, 'false'.\n Logon: $sessionid, $nonce\nuploadsid --" . $uploadsid;
> $session->flush();
>
>
>
> #########################################################
> # here I am following your code:
>
> ## now generate the html page that will initialize the session
> ## start with the session cookie:
>
> my $cookie = CGI::Cookie->new(-name => 'gbrowse_sess',
> -path => '/var/www/HBCR/gbrowse2/',
> -expires => '+1M',
> -value => $session->id );
>
> ## some JSON data is required for calling the java script:
> # user or username in GB? I give both
> my $result = to_json { userOK => 1,
> sessionid => $sessionid_from_user,
> username => $userid,
> message => 'login ok',
> };
> ## import required javascript functions
> my $htmlhead = "<script src=\"https://mseqdr.org/gbrowse2/js/login.js\" type=\"text/javascript\"></script>
> <script src=\"https://mseqdr.org/gbrowse2/js/controller.js\" type=\"text/javascript\"></script>\n";
>
> print header(-type=>"text/html", -cookie=> $cookie);
> print start_html(-head=>$htmlhead);
> print STDERR "Found existing user with ID: $userid / $validated_login_id <br>\n$fullname $email\n<br> PHP SessionID: $id2 <br>\nGbrowse SessionID:$sessionid_from_user -- $sessionid \n".$session->id;
>
> print "\n\n<script type=\"text/javascript\">\n";
> print "var p = $result;\n";
> print "login_load_account(\"$myurl\", p);\n";
> print "</script>\n";
> print end_html();
> }
>
>
>
>
could you have a look at:
https://github.com/mdondrup/GBrowse/blob/master/cgi-bin/samlPostEpr
and tell me if that helps you. The interaction with the gbrowse api starts at line 45.
To avoid a having to rewrite and use the gbrowse main cgi as
a receiver for the POST message I added another endpoint script. Apart from receiving and
validating the encrypted SAML code it also contains the logic to create a gbrowse user and
session and to initialize the session and to 'redirect' via java script. Note that we trust the
SAML authentication in that we will also create a new gbrowse user in the database if there
is not already such an account.
Please let me know if you have any further questions.
Best
Michael
Michael Dondrup
Postdoctoral fellow
Sea Lice Research Centre/Department of Informatics
University of Bergen
Thormøhlensgate 55, N-5008 Bergen,
Norway
On Jan 30, 2015, at 2:35 PM, Lishuang Shen wrote:
> Hello:
>
> Regarding your 3rd party logon. I need your advice.
>
> http://sourceforge.net/p/gmod/mailman/message/33295297/
>
>
>
> I am following similar strategyto yours above for 3rd party login done with PHP. I handled
> the information with perl PHP::session and able to read and validate the PHP generated
> session and validated with session information in Gbrowse mysql.
>
> I use database to store the user and session information, not using files.
> So I am trying to activate my validated session information into Gbrowse.
> But stuck here regarding how to set cookie. It will jump to the gbrowse page, but not able to logon.
>
>
>
>
> Thank you,
>
> Lishuang
>
>
>
>
> #########################################################
> # I am trying to use directly the part of gbrowse login, for some infoirmation:
>
> my $nonce = Bio::Graphics::Browser2::Util->generate_id;
> my $ip = CGI::remote_addr(); ## OK for ssl?
> $session-> set_nonce($nonce,$ip, 1); #set_nonce($nonce,$ip,$remember);
> $session-> using_openid('false');
> my $uploadsid = $userdb-> get_uploads_id($userid);
>
> print STDERR "id= $sessionid_from_user, IP: $ip $nonce -- username =", $session->username;
> print STDERR "\nauthorize_user: $userid, $sessionid_from_user ". $session->id . " 2, 'false'.\n Logon: $sessionid, $nonce\nuploadsid --" . $uploadsid;
> $session->flush();
>
>
>
> #########################################################
> # here I am following your code:
>
> ## now generate the html page that will initialize the session
> ## start with the session cookie:
>
> my $cookie = CGI::Cookie->new(-name => 'gbrowse_sess',
> -path => '/var/www/HBCR/gbrowse2/',
> -expires => '+1M',
> -value => $session->id );
>
> ## some JSON data is required for calling the java script:
> # user or username in GB? I give both
> my $result = to_json { userOK => 1,
> sessionid => $sessionid_from_user,
> username => $userid,
> message => 'login ok',
> };
> ## import required javascript functions
> my $htmlhead = "<script src=\"https://mseqdr.org/gbrowse2/js/login.js\" type=\"text/javascript\"></script>
> <script src=\"https://mseqdr.org/gbrowse2/js/controller.js\" type=\"text/javascript\"></script>\n";
>
> print header(-type=>"text/html", -cookie=> $cookie);
> print start_html(-head=>$htmlhead);
> print STDERR "Found existing user with ID: $userid / $validated_login_id <br>\n$fullname $email\n<br> PHP SessionID: $id2 <br>\nGbrowse SessionID:$sessionid_from_user -- $sessionid \n".$session->id;
>
> print "\n\n<script type=\"text/javascript\">\n";
> print "var p = $result;\n";
> print "login_load_account(\"$myurl\", p);\n";
> print "</script>\n";
> print end_html();
> }
>
>
>
>