Skip to content

Commit

Permalink
Merge pull request #25 from duncanbarnes/master
Browse files Browse the repository at this point in the history
Patch for Mantis v2.25 & PHP8, resolves 8 open issues with this plugin
  • Loading branch information
alleen authored Feb 10, 2022
2 parents c84b36b + dbc20d0 commit 0ef930f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
27 changes: 26 additions & 1 deletion GoogleOauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,32 @@ function resources() {
return '
<meta name="redirectUri" content="' . plugin_config_get( 'redirect_uri' ) . '" />
<meta name="clientId" content="' . plugin_config_get( 'clientId' ) . '" />
<script type="text/javascript" src="plugins/GoogleOauth/pages/assets/js/plugin.js"></script>
<style>
#plugin_googleoauth {
margin-top:20px;
padding-top:20px;
border-top: 1px solid #CCC;
text-align:right;
}
#plugin_googleoauth a {
background: url('.plugin_file("google_signin_normal.png").');
background-size:contain;
background-repeat:no-repeat;
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
display: inline-block;
height: 46px;
width: 191px;
margin-right:25px;
}
#plugin_googleoauth a:hover {
background: url('.plugin_file("google_signin_pressed.png").');
background-size:contain;
background-repeat:no-repeat;
}
</style>
<script type="text/javascript" src="'.plugin_file("plugin.js").'"></script>
';
}
}
Binary file added files/google_signin_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added files/google_signin_pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions files/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$(document).ready(function () {
//allow admin to set password directly
//include input for new password
var redirectUri = $("meta[name='redirectUri']").attr('content');
var clientId = $("meta[name='clientId']").attr('content');
// (disabled) Send all the params
//var url = window.location.href
//var state = ( url.match(/\?(.+)$/) || [,''])[1];
// Send just the return param value
var urlParams = new URLSearchParams(window.location.search);
var state = urlParams.get('return') || '';
var html = '<div id="plugin_googleoauth">\
<a href="https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=' + redirectUri + '&client_id=' + clientId + '&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&access_type=offline&prompt=consent&state=' + state + '">Sign in with google</a>\
</div>';
$(html).insertAfter('#login-form');
});
19 changes: 0 additions & 19 deletions pages/assets/js/plugin.js

This file was deleted.

5 changes: 4 additions & 1 deletion pages/config_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

plugin_config_set('clientId', strip_tags(gpc_get_string('prefClientID')));
plugin_config_set('clientSecret', strip_tags(gpc_get_string('prefClientSecret')));
plugin_config_set('redirect_uri', config_get('path')."plugins/GoogleOauth/pages/redirect.php");

$redirecturi = config_get('path');
if(substr($redirecturi, -1) == '/') $redirecturi = rtrim($redirecturi,'/');
plugin_config_set('redirect_uri', $redirecturi.plugin_page( 'redirect'));

form_security_purge( 'plugin_GoogleOauth_config_update' );
print_successful_redirect( plugin_page( 'config', true ) );
6 changes: 3 additions & 3 deletions pages/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
$client = new Google_Client();

$client->setApplicationName("MantisBT Google authentication module");
$client->setClientId(config_get(plugin_GoogleOauth_clientId));
$client->setClientSecret(config_get(plugin_GoogleOauth_clientSecret));
$client->setRedirectUri(config_get(plugin_GoogleOauth_redirect_uri));
$client->setClientId(config_get( 'plugin_GoogleOauth_clientId' ));
$client->setClientSecret(config_get( 'plugin_GoogleOauth_clientSecret' ));
$client->setRedirectUri(config_get( 'plugin_GoogleOauth_redirect_uri'));

$objOAuthService = new Google_Service_Oauth2($client);

Expand Down

0 comments on commit 0ef930f

Please sign in to comment.