Dancer2-Plugin-Auth-OAuth

 view release on metacpan or  search on metacpan

lib/Dancer2/Plugin/Auth/OAuth/Provider/AzureAD.pm  view on Meta::CPAN


  if ($self->provider_settings->{urls}{user_info}) {
    my $resp = $self->{ua}->request(
      GET $self->provider_settings->{urls}{user_info},
      Authorization => "Bearer ".$session_data->{azuread}{access_token},
      Accept => "application/json"
    );

    if ( $resp->is_success ) {
      my $user = $self->_stringify_json_booleans(
        JSON::MaybeXS::decode_json( $resp->decoded_content )
      );
      $session_data->{azuread}{user_info} = $user;
    } else {
      # To-Do: logging error
    }
  }
  $session->write('oauth', $session_data);
  return 1;
}

lib/Dancer2/Plugin/Auth/OAuth/Provider/AzureAD.pm  view on Meta::CPAN


Generic provider for Microsoft OAuth2.

Note that you will undoubtably need to change some or all of the options above.

After login, the following session key will have contents: C<{oauth}{azuread}>

The token will probably be in C<{id_token}>

When log in has occured, the provider attempts to decode the resulting token
for information about the user. All of the decoded information can be found in
the session key: C<{oauth}{azuread}{login_info}>

The login email address, for example, will probably be in a key called
C<{unique_name}>

If the user_info option is defined (which it is by default!), a corresponding
call is made to that URL to find out more information about the user. This is
stashed in the session key C<{oauth}{azuread}{user_info}>

=head1 ADDING TENANT ID

lib/Dancer2/Plugin/Auth/OAuth/Provider/Google.pm  view on Meta::CPAN


    my $session_data = $session->read('oauth');

    my $resp = $self->{ua}->request(
        GET $self->provider_settings->{urls}{user_info},
        Authorization => "Bearer ".$session_data->{google}{access_token}
    );

    if( $resp->is_success ) {
        my $user = $self->_stringify_json_booleans(
            JSON::MaybeXS::decode_json( $resp->decoded_content )
        );
        $session_data->{google}{user_info} = $user;
        $session->write('oauth', $session_data);
    }
}

1;

lib/Dancer2/Plugin/Auth/OAuth/Provider/Linkedin.pm  view on Meta::CPAN

        $self->provider_settings->{urls}{user_info} =~ s/~\?/~$fields?/;
    }

    my $resp = $self->{ua}->request(
        GET $self->provider_settings->{urls}{user_info},
        Authorization => "Bearer ".$session_data->{linkedin}{access_token}
    );

    if( $resp->is_success ) {
        my $user = $self->_stringify_json_booleans(
            JSON::MaybeXS::decode_json( $resp->decoded_content )
        );
        $session_data->{linkedin}{user_info} = $user;
        $session->write('oauth', $session_data);
    }
}

1;

lib/Dancer2/Plugin/Auth/OAuth/Provider/Salesforce.pm  view on Meta::CPAN


    my $session_data = $session->read('oauth');

    my $resp = $self->{ua}->request(
        GET $session_data->{salesforce}{id} . '?access_token=' .
        $session_data->{salesforce}{access_token}
    );

    if( $resp->is_success ) {
        my $user = $self->_stringify_json_booleans(
            JSON::MaybeXS::decode_json( $resp->decoded_content )
        );
        $session_data->{salesforce}{user_info} = $user;
        $session->write('oauth', $session_data);
    }
}

1;

lib/Dancer2/Plugin/Auth/OAuth/Provider/Stackexchange.pm  view on Meta::CPAN


    my $resp = $self->{ua}->request(
        GET $provider_settings->{urls}{user_info}.
            "?access_token=".$session_data->{stackexchange}{access_token}.
            "&site=".$provider_settings->{site}.
            "&key=".$provider_settings->{tokens}{key}
    );

    if( $resp->is_success ) {
        my $user = $self->_stringify_json_booleans(
            JSON::MaybeXS::decode_json( $resp->decoded_content )
        );
        $session_data->{stackexchange}{user_info} = $user;
        $session->write('oauth', $session_data);
    }
}

1;

lib/Dancer2/Plugin/Auth/OAuth/Provider/Twitter.pm  view on Meta::CPAN

        token           => $session_data->{twitter}{access_token},
        token_secret    => $session_data->{twitter}{access_token_secret},
        request_method  => 'GET',
        request_url     => 'https://api.twitter.com/1.1/account/verify_credentials.json',
    );
    $request->sign;

    my $resp = $self->ua->request(GET $request->to_url);
    if ($resp->is_success) {
        my $user = $self->_stringify_json_booleans(
            JSON::MaybeXS::decode_json( $resp->decoded_content )
        );
        $session_data->{twitter}{user_info} = $user;
        $session->write('oauth', $session_data);
    }
}

1;



( run in 0.349 second using v1.01-cache-2.11-cpan-26ccb49234f )