Skip to content

Commit d5e3ac1

Browse files
author
csteipp
committed
allow dynamic callback url, fix signing post params
1 parent c00534c commit d5e3ac1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

MWOAuthClient.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
include_once './OAuth.php'; // reference php library from oauth.net
3+
include_once __DIR__ . '/OAuth.php'; // reference php library from oauth.net
44

55
function wfDebugLog( $method, $msg) {
66
// Uncomment this if you want debuggging info from the OAuth library
@@ -47,6 +47,9 @@ class MWOAuthClient {
4747
// Any extra params in the call that need to be signed
4848
private $extraParams = array();
4949

50+
// url, defaults to oob
51+
private $callbackUrl = 'oob';
52+
5053
// Track the last random nonce generated by the OAuth lib, used to
5154
// verify /identity response isn't a replay
5255
private $lastNonce;
@@ -71,6 +74,10 @@ public function setExtraParams( $params ) {
7174
$this->extraParams = $params;
7275
}
7376

77+
public function setCallback( $url ) {
78+
$this->callbackUrl = $url;
79+
}
80+
7481
/**
7582
* First part of 3-legged OAuth, get the request Token.
7683
* Redirect your authorizing users to the redirect url, and keep
@@ -79,7 +86,7 @@ public function setExtraParams( $params ) {
7986
* @return array (redirect, request/temp token)
8087
*/
8188
public function initiate() {
82-
$initUrl = $this->config->endpointURL . '/initiate&format=json&oauth_callback=oob';
89+
$initUrl = $this->config->endpointURL . '/initiate&format=json&oauth_callback=' . urlencode( $this->callbackUrl );
8390
$data = $this->makeOAuthCall( null, $initUrl );
8491
$return = json_decode( $data );
8592
if ( $return->oauth_callback_confirmed !== 'true' ) {
@@ -161,6 +168,10 @@ public function makeOAuthCall( $token, $url, $isPost = false, $postFields = fals
161168
}
162169
$params += $this->extraParams;
163170

171+
if ( $isPost && $postFields ) {
172+
$params += $postFields;
173+
}
174+
164175
$method = $isPost ? 'POST' : 'GET';
165176
$req = OAuthRequest::from_consumer_and_token(
166177
$this->consumerToken,

0 commit comments

Comments
 (0)