Thanks Master for pointing out my issue and i was able to redirect to my OKTA authorization page and getting the authorization code but not able to capture the authorization code in order to get the access_token as per the documentation. How can i capture the authorization code value? Can you please suggest where i need to make changes? I have configured redirect URI in my code and authorization server same. Please check my current webapp.pm , my url response in request URL mode and current error. The error is obvious as i was not able to grab the incoming authorization code

webapp.pm

package webapp; use Dancer2; use Op; use Op1; use URI; use Net::OAuth2::Client; use HTML::Entities; our $VERSION = '0.1'; sub client { Net::OAuth2::Profile::WebServer->new( client_id => 'xxxxxxxxxxxxxxxxxx', client_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +, authorize_url => 'https://dev.oktapreview.com/oauth2/ +v1/authorize', access_token_url => 'https://dev.oktapreview.com/oauth2/v1/token +', response_type => 'code', redirect_uri => uri_for ("/"), grant_type => 'authorization_code', scope => 'openid', state => '1234', ); } get '/:site_id' => sub { my $id = route_parameters->get('site_id'); print "$id" . "\n"; redirect client(params->{$id})->authorize; my $code = params->{code}; print "$code" . "\n"; }; get '/got/:site_id' => sub { defined params->{code} or return html_page("Error: Missing access code"); my $id = route_parameters->get('site_id'); my $site_id = params->{$id}; my $site_id = params->{$id}; my $access_token = client($site_id)->get_access_token(params->{cod +e}); return html_page("Error: " . $access_token->to_string) if $access_token->{error}; my $content = "<h2>Access token retrieved successfully!</h2>\n" . '<p>'.encode_entities($access_token->to_string)."</p +>\n"; $content .= "<h2>State passthru</h2>" . encode_entities(params-> +{state}) if params->{state}; $content .= "<h2>HD passthru</h2>" . encode_entities(params->{hd +}) if params->{hd}; my $this_site = config->{sites}{$site_id}; my $response = $access_token->get($this_site->{protected_resource +_url} || $this_site->{protected_resource_path}); if ($response->is_success) { $content .= "<h2>Protected resource retrieved successfully!</h +2>\n" . '<p>'.encode_entities($response->decoded_content). +'</p>'; } else { $content .= '<p>Error: '. $response->status_line."</p>\n"; } $content =~ s[\n][<br/>\n]g; html_page($content); }; get '/' => sub { 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 success page with authorization code

https://testchandan.com:5001/?code=PVPDqlmasALToCPMZJJVb64rP4SY9cxO2Bu7YzGQqcg&state=1234

My incognito chrome browser headers

General Request URL: https://testchandan.com:5001/?code=PVPDqlmasALToCPMZJJVb6 +4rP4SY9cxO2Bu7YzGQqcg&state=1234 Request Method: GET Status Code: 200 OK Remote Address: 192.168.1.6:5001 Referrer Policy: strict-origin-when-cross-origin Response Header Content-Length: 1252 Content-Type: text/html; charset=UTF-8 Date: Fri, 18 Jun 2021 06:32:58 GMT Server: HTTP::Server::PSGI Server: Perl Dancer2 0.301004 Request Headers Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/av +if,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q +=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Connection: keep-alive Cookie: plack_session=ba1d0d240ba3ed6c6fca13c240c758a6c812200d Host: testchandan.com:5001 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537. +36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36 Query String parameters code: PVPDqlmasALToCPMZJJVb64rP4SY9cxO2Bu7YzGQqcg state: 1234

My current error

Error 500 - Internal Server Error Runtime Error Undefined subroutine &webapp::html_page called at C:/Users/503004671/D +ocuments/Perl/Synchrony-Perl/webapp/bin/../lib/webapp.pm line 67. C:/Users/503004671/Documents/Perl/Synchrony-Perl/webapp/bin/../lib/web +app.pm around line 67 62 }; 63 64 get '/got/:site_id' => sub { 65 66 defined params->{code} 67 or return html_page("Error: Missing access code"); 68 my $id = route_parameters->get('site_id'); 69 70 my $site_id = params->{$id}; 71 72 my $access_token = client($site_id)->get_access_token(params +->{code});

In reply to Re^14: How can i capture the site_id in Dancer 2 app? by chandantul
in thread How can i capture the site_id in Dancer 2 app? by chandantul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.