From 747bc623818a34ed7048e1fd9e2ac10046167a33 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 1 Jul 2019 14:58:57 +0200 Subject: [PATCH] encode client secret for graph and management api --- cloud/microsoft/office365/custom/graphapi.pm | 3 ++- cloud/microsoft/office365/custom/managementapi.pm | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud/microsoft/office365/custom/graphapi.pm b/cloud/microsoft/office365/custom/graphapi.pm index 8849d7995..9df22817c 100644 --- a/cloud/microsoft/office365/custom/graphapi.pm +++ b/cloud/microsoft/office365/custom/graphapi.pm @@ -145,10 +145,11 @@ sub get_access_token { if ($has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10)) { my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_client_secret = $uri->encode($self->{client_secret}); my $encoded_graph_endpoint = $uri->encode($self->{graph_endpoint} . '/.default'); my $post_data = 'grant_type=client_credentials' . '&client_id=' . $self->{client_id} . - '&client_secret=' . $self->{client_secret} . + '&client_secret=' . $encoded_client_secret . '&scope=' . $encoded_graph_endpoint; $self->settings(); diff --git a/cloud/microsoft/office365/custom/managementapi.pm b/cloud/microsoft/office365/custom/managementapi.pm index 01d2433e1..7a5d8e8d3 100644 --- a/cloud/microsoft/office365/custom/managementapi.pm +++ b/cloud/microsoft/office365/custom/managementapi.pm @@ -143,10 +143,11 @@ sub get_access_token { if ($has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10)) { my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_client_secret = $uri->encode($self->{client_secret}); my $encoded_management_endpoint = $uri->encode($self->{management_endpoint}); my $post_data = 'grant_type=client_credentials' . '&client_id=' . $self->{client_id} . - '&client_secret=' . $self->{client_secret} . + '&client_secret=' . $encoded_client_secret . '&resource=' . $encoded_management_endpoint; $self->settings();