Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Unable to execute the get method from app.psgi file for Dancer2 app.

by chandantul (Scribe)
on Jun 21, 2021 at 06:54 UTC ( [id://11134098]=perlquestion: print w/replies, xml ) Need Help??

chandantul has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Unable to execute the get method from app.psgi file for Dancer2 app.
  • Download Code

Replies are listed 'Best First'.
Re: Unable to execute the get method from app.psgi file for Dancer2 app.
by 1nickt (Canon) on Jun 21, 2021 at 11:01 UTC

    my $id = route_parameters->get('site_id'); redirect client(params->{$id})->authorize;

    You are storing the value of the site_id param in $id. Then you are for some reason not using that variable, but fetching the value again ... but the second time you are looking for a parameter with the same name as the value.


    The way forward always starts with a minimal test.

      Hello Master, Sorry, Please check the latest code that is working fine in webapp.pm in order to generate the access token but my goal is to run the code snippet from app.psgi and land to main page query2.tt and export the access_token from app.psgi and use it for different subroutine in op.pm through webapp.pm. is that possible for you to help me Master?

      My current app.psgi. and only last line is working webapp->to_app;

      #!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use webapp; use Net::OAuth2::Client; use Plack::Builder; use Plack::Request; use Dancer2; use URI; use HTML::Entities; use Data::Dumper; builder { #get '/:site_id' => sub { # my $id = route_parameters->get('site_id'); # print "$id" . "\n"; #}; get '/:site_id' => sub { my $id = route_parameters->get('site_id'); redirect client(params->{$id})->authorize; }; get '/got/:site_id' => sub { my $p = params->{code}; #template 'query2' => { 'title' => 'webapp' }; defined params->{code} or print "Error: Missing access code"; my $id = route_parameters->get('site_id'); my $site_id = params->{$id}; #my $site_id = params->{site_id}; my $access_token = client($site_id)->get_access_token(params->{cod +e}); print "Error: " . $access_token->to_string if $access_token->{err +or}; my $accestk = $access_token->to_string; my $content = "<h2>Access token retrieved successfully!</h2>\n +" . '<p>'.encode_entities($access_token->to_string)."</p +>\n"; #template 'query2' => { 'title' => 'webapp' }; $content =~ s[\n][<br/>\n]g; print "My content: $content" . "\n"; }; sub client ($){ my $id = route_parameters->get('site_id'); my $site_id = $id; #my $site_config = config->{sites}{$site_id} || {}; my $redirect = uri_for("/got/$site_id"); Net::OAuth2::Profile::WebServer->new( client_id => 'xxxxxxxxxxxxxxxxxxxxx', client_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xx', authorize_url => 'https://dev.oktapreview.com/oauth2/ +v1/authorize', access_token_url => 'https://dev.oktapreview.com/oauth2/v1/token +', response_type => 'code', grant_type => 'authorization_code', scope => 'openid', state => '1234', redirect_uri => $redirect ); } webapp->to_app; }

      My urrent webapp.pm

      package webapp; use Dancer2; use Op; use Op1; use URI; use Net::OAuth2::Client; use HTML::Entities; use Data::Dumper; our $VERSION = '0.1'; get '/:site_id' => sub { route_parameters->get('site_id'); template 'query2' => { 'title' => 'webapp' }; }; post '/'=> sub { my $r2 = Op::result4({OKTAUsersList => param('OKTA-Users-List'), Email => param('Email')}); template result2 => { title => 'webapp', result2 => $r2 } }; true;

      My query2.tt

      <form id="f1" method="post" action="/"> <style> body { background-color: #ABBAEA; } div { height: 200px; background-color: #FBD603; } </style> <body> <div> <input type="radio" name="OKTAUsersList"> <label for="OKTAUsersList">OKTA-Users-List</label> <label for="Email">Recipient Email</label> <input id="email" name="Email"> <button>Submit</button> </div> </body> </form>

        Why don;t you have your route declarations (and the client() sub for that matter) in webapp.pm ? I do not ever place route declarations inside the builder() sub; I've never seen that. My app.psgi is almost empty except for use statements and to_app().


        The way forward always starts with a minimal test.
        A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11134098]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-23 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found