@@ -54,34 +54,44 @@ Or you authenticate, like this:
54
54
``` php
55
55
session_start();
56
56
57
- if (! isset($_GET['oauth_verifier '])) {
58
- // gets a request token
57
+ if (! isset($_SESSION['oauth_token '])) {
58
+ // get the request token
59
59
$reply = $cb->oauth_requestToken(array(
60
60
'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
61
61
));
62
62
63
- // stores it
63
+ // store the token
64
64
$cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
65
65
$_SESSION['oauth_token'] = $reply->oauth_token;
66
66
$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
67
+ $_SESSION['oauth_verify'] = true;
67
68
68
- // gets the authorize screen URL
69
+ // redirect to auth website
69
70
$auth_url = $cb->oauth_authorize();
70
71
header('Location: ' . $auth_url);
71
72
die();
72
73
73
- } elseif (! isset($_SESSION['oauth_verified '])) {
74
- // gets the access token
74
+ } elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify '])) {
75
+ // verify the token
75
76
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
77
+ unset($_SESSION['oauth_verify']);
78
+
79
+ // get
A727
the access token
76
80
$reply = $cb->oauth_accessToken(array(
77
81
'oauth_verifier' => $_GET['oauth_verifier']
78
82
));
79
- // store the authenticated token, which may be different from the request token (!)
83
+
84
+ // store the token (which is different from the request token!)
80
85
$_SESSION['oauth_token'] = $reply->oauth_token;
81
86
$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
82
- $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
83
- $_SESSION['oauth_verified'] = true;
87
+
88
+ // send to same URL, without oauth GET parameters
89
+ header('Location: ' . basename(__FILE__));
90
+ die();
84
91
}
92
+
93
+ // assign access token on each page load
94
+ $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
85
95
```
86
96
87
97
### 1.1. Application-only auth
0 commit comments