-
Notifications
You must be signed in to change notification settings - Fork 8
/
redirect.php
165 lines (145 loc) · 5.9 KB
/
redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
require( '../../config.php' );
$code = '';
$state = '';
$error = false;
$error_code = '';
$oauth_token = false;
$oauth_verifier = false;
$auth_service = optional_param( 'auth_service', '', PARAM_TEXT );
if ( !empty( $auth_service ) ) {
switch ( $auth_service ) {
case 'facebook':
$code = optional_param( 'code', '', PARAM_TEXT );
if ( empty( $code ) ) {
$error_inurl = optional_param( 'error', '', PARAM_TEXT );
switch ( $error_inurl ) {
case 'access_denied':
$error = true;
$error_code = $error_inurl;
break;
}
$error_inurl2 = optional_param( 'error_description', '', PARAM_TEXT );
if ( !empty( $error_inurl2 ) ) {
$error = true;
$error_code .= ' - ' . urldecode( $error_inurl2 );
}
if ( empty( $error_inurl ) ) {
$error = true;
$error_code = get_string( 'auth_lenauth_empty_code_param', 'auth_lenauth' );
}
}
break;
case 'google':
$code = optional_param( 'code', '', PARAM_TEXT );
if ( empty( $code ) ) {
$error_inurl = optional_param( 'error', '', PARAM_TEXT );
switch ( $error_inurl ) {
case 'access_denied':
$error = true;
$error_code = $error_inurl;
break;
}
if ( empty( $error_inurl ) ) {
$error = true;
$error_code = get_string( 'auth_lenauth_empty_code_param', 'auth_lenauth' );
}
}
break;
case 'yahoo1':
$code = $auth_service;
$oauth_token = false;
if ( isset( $_REQUEST['oauth_token'] ) ) $oauth_token = optional_param( 'oauth_token', '', PARAM_TEXT );
$oauth_verifier = false;
if ( isset( $_REQUEST['oauth_verifier'] ) ) $oauth_verifier = optional_param( 'oauth_verifier', '', PARAM_TEXT );
break;
case 'yahoo2':
$code = optional_param( 'code', '', PARAM_TEXT );
$state = optional_param( 'state', '', PARAM_TEXT );
break;
case 'twitter':
$code = $auth_service;
$oauth_token = false;
if ( isset( $_REQUEST['oauth_token'] ) ) $oauth_token = optional_param( 'oauth_token', '', PARAM_TEXT );
$oauth_verifier = false;
if ( isset( $_REQUEST['oauth_verifier'] ) ) $oauth_verifier = optional_param( 'oauth_verifier', '', PARAM_TEXT );
break;
case 'vk':
$code = optional_param( 'code', '', PARAM_TEXT );
if ( empty( $code ) ) {
$error_inurl = optional_param( 'error', '', PARAM_TEXT );
switch ( $error_inurl ) {
case 'invalid_request':
$error = true;
$error_code = $error_inurl;
break;
}
$error_inurl2 = optional_param( 'error_description', '', PARAM_TEXT );
if ( !empty( $error_inurl2 ) ) {
$error = true;
$error_code .= ' - ' . urldecode( $error_inurl2 );
}
if ( empty( $error_inurl ) ) {
$error = true;
$error_code = get_string( 'auth_lenauth_empty_code_param', 'auth_lenauth' );
}
}
break;
case 'yandex':
$code = optional_param( 'code', '', PARAM_INT );
if ( empty( $code ) ) {
$error_inurl = optional_param( 'error', '', PARAM_TEXT );
if ( !empty( $error_inurl ) ) {
$error = true;
$error_code = $error_inurl;
}
if ( empty( $error_inurl ) ) {
$error = true;
$error_code = get_string( 'auth_lenauth_empty_code_param', 'auth_lenauth' );
}
}
break;
case 'mailru':
$code = optional_param( 'code', '', PARAM_TEXT );
if ( empty( $code ) ) {
$error_inurl = optional_param( 'error', '', PARAM_TEXT );
if ( !empty( $error_inurl ) ) {
$error = true;
$error_code = $error_inurl;
}
if ( empty( $error_inurl ) ) {
$error = true;
$error_code = get_string( 'auth_lenauth_empty_code_param', 'auth_lenauth' );
}
}
break;
/*case 'ok':
$code = optional_param( 'code', '', PARAM_TEXT );
if ( empty( $code ) ) {
$error = true;
}
break;*/
}
}
if ( empty( $error ) ) {
global $CFG;
$loginurl = $CFG->wwwroot . '/login/index.php';
if ( !empty( $CFG->alternateloginurl ) ) {
$loginurl = $CFG->alternateloginurl;
}
/**
* @see auth.php#loginpage_hook()
*/
$moodle_url_params = array( 'oauthcode' => $code, 'authprovider' => $auth_service );
if ( !empty( $state ) ) $moodle_url_params['state'] = $state;
if ( $oauth_token ) $moodle_url_params['oauth_token'] = $oauth_token;
if ( $oauth_verifier ) $moodle_url_params['oauth_verifier'] = $oauth_verifier;
$url = new moodle_url( $loginurl, $moodle_url_params );
} else {
$moodle_index_url_errors = array( 'oauth_failure' => $error );
if ( !empty( $error_code ) ) {
$moodle_index_url_errors['code'] = $error_code;
}
$url = new moodle_url( '/', $moodle_index_url_errors );
}
redirect( $url );