Projet

Général

Profil

Révision 286092dc

Ajouté par Assos Assos il y a environ 6 ans

Added OAuth2 modules

Voir les différences:

drupal7/sites/all/modules/oauth2_authentication/LICENSE.txt
1
                    GNU GENERAL PUBLIC LICENSE
2
                       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
                            Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Lesser General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

  
59
                    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

  
114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

  
172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

  
229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
                            NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
                     END OF TERMS AND CONDITIONS
281

  
282
            How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
292

  
293
    <one line to give the program's name and a brief idea of what it does.>
294
    Copyright (C) <year>  <name of author>
295

  
296
    This program is free software; you can redistribute it and/or modify
297
    it under the terms of the GNU General Public License as published by
298
    the Free Software Foundation; either version 2 of the License, or
299
    (at your option) any later version.
300

  
301
    This program is distributed in the hope that it will be useful,
302
    but WITHOUT ANY WARRANTY; without even the implied warranty of
303
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
    GNU General Public License for more details.
305

  
306
    You should have received a copy of the GNU General Public License along
307
    with this program; if not, write to the Free Software Foundation, Inc.,
308
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309

  
310
Also add information on how to contact you by electronic and paper mail.
311

  
312
If the program is interactive, make it output a short notice like this
313
when it starts in an interactive mode:
314

  
315
    Gnomovision version 69, Copyright (C) year name of author
316
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
    This is free software, and you are welcome to redistribute it
318
    under certain conditions; type `show c' for details.
319

  
320
The hypothetical commands `show w' and `show c' should show the appropriate
321
parts of the General Public License.  Of course, the commands you use may
322
be called something other than `show w' and `show c'; they could even be
323
mouse-clicks or menu items--whatever suits your program.
324

  
325
You should also get your employer (if you work as a programmer) or your
326
school, if any, to sign a "copyright disclaimer" for the program, if
327
necessary.  Here is a sample; alter the names:
328

  
329
  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
  `Gnomovision' (which makes passes at compilers) written by James Hacker.
331

  
332
  <signature of Ty Coon>, 1 April 1989
333
  Ty Coon, President of Vice
334

  
335
This General Public License does not permit incorporating your program into
336
proprietary programs.  If your program is a subroutine library, you may
337
consider it more useful to permit linking proprietary applications with the
338
library.  If this is what you want to do, use the GNU Lesser General
339
Public License instead of this License.
drupal7/sites/all/modules/oauth2_authentication/README.html
1
<!DOCTYPE html>
2
<html>
3
  <head>
4
    <title>Documentation for Drupal's OAuth2 Authentication Module</title>
5
    <meta charset="UTF-8">
6
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
  </head>
8
  <body>
9
    <h1>Documentation for Drupal's OAuth2 Authentication Module</h1>
10

  
11
    <h2>Purpose</h2>
12
    <p>
13
      <a href="https://www.drupal.org/project/oauth2_authentication">OAuth2 Authentication</a> allows users to log into your Drupal site authenticating against a remote <a href="https://en.wikipedia.org/wiki/Identity_provider">identity provider (IDP)</a> via <a href="https://en.wikipedia.org/wiki/OAuth2#OAuth_2.0">OAuth2</a>.
14
    </p>
15
    <p>
16
      That is, if a user's credentials can be used to retrieve a valid <a href="https://en.wikipedia.org/wiki/Access_token">access token</a>, he/she will be logged into the site with those credentials and the token will be added to his/her session.  If the user doesn't exist yet, it will be created.
17
    </p>
18

  
19
    <h2>Disclaimer</h2>
20
    <p>
21
      In doing this, we're making the assumption that resource requesters are actually resource owners.  Generally, one shouldn't make that assumption as <strong>OAuth2 is an authorization mechanism, not an authentication mechanism</strong>.
22
    </p>
23

  
24
    <p>
25
      If you found this module looking for a standard way to have users log in via OAuth2, then you should probably go with <a href="https://www.drupal.org/project/openid_connect"> OpenID Connect</a> instead.  It provides a proper identity layer on top of OAuth2.  Think of it like the evolution of <a href="https://en.wikipedia.org/wiki/Security_Assertion_Markup_Language">SAML</a>.  This module is meant for those that don't have access to an OpenID Connect server, do have access to an IDP that speaks OAuth2, and can trust the environment in which all of it operates.
26
    </p>
27

  
28
    <p>
29
      If you haven't considered the security implications of using this module, and you don't control the environment in which it's running, then you shouldn't be using it.  For example, you probably don't want to do this sort of thing on a mobile environment as it can't be trusted to the same extent as a Drupal site behind a corporate firewall.
30
    </p>
31

  
32
    <p>
33
      If you made it this far, and are still considering using the module, then make sure you've read and understood the following articles.
34
    </p>
35

  
36
    <ul>
37
      <li>
38
        <a href="http://blog.api-security.org/2013/02/why-oauth-it-self-is-not-authentication.html">Why OAuth it self is not an authentication framework?</a>
39
      </li>
40
      <li>
41
        <a href="http://www.thread-safe.com/2012/01/problem-with-oauth-for-authentication.html">The problem with OAuth for Authentication</a>
42
      </li>
43
    </ul>
44

  
45
    <p>
46
      It also wouldn't hurt to study the official <a href="http://tools.ietf.org/html/rfc6819">OAuth 2.0 Threat Model and Security Considerations</a>.
47
    </p>
48

  
49
    <h2>Initial Set-Up</h2>
50
    <ol>
51
      <li>
52
        Install and enable the <a href="https://www.drupal.org/project/oauth2_client">OAuth2 Client</a> and <a href="https://www.drupal.org/project/oauth2_authentication"> OAuth2 Authentication</a> modules <a href="https://www.drupal.org/documentation/install/modules-themes/modules-7">as you would any other</a>.
53
      </li>
54
      <li>
55
        If you wish to override any of the methods in the <em>OAuth2AuthenticationClient</em> class to change the module's behaviour, create another class that extends it and implement the desired methods.  This is best done in a custom module for your site, something like <em>Sitename</em> Authentication (<em>sitename</em>_authentication) where <em>S/sitename</em> is the name of your site.
56
      </li>
57
      <li>
58
        Surf to the configuration page over at Home » Administration » Configuration » Web services » OAuth2 Authentication to configure your token endpoint.  This section is mandatory while the others are optional.  They contain sane defaults, but look over all of it to make sure it's what you need for your set-up.
59
      </li>
60
      <li>
61
        If you subclassed <em>OAuth2AuthenticationClient</em>, replace the default class name in Miscellaneous Settings » Client Class with the name of your new class.
62
      </li>
63
      <li>Hit the <em>Save configuration</em> button to save your settings.</li>
64
      <li>Enjoy!</li>
65
    </ol>
66

  
67
    <h2>Notes</h2>
68

  
69
    <ul>
70
      <li>
71
        When an existing local user logs in, the module will attempt to get an access token for him/her.  On success, the token will be added to the user's session.  On failure, the user will still be logged in, but will not get a token.  Whenever a request to get a token is made, the results are reported in the log.
72
      </li>
73
      <li>
74
        Once you've got this set up, you'll have to ensure that <a href="https://www.drupal.org/node/2292623">the Web-services client module you're using</a> supports the OAuth2 protocol (i.e. token access to resources).  If you're already using one that doesn't, you'll have to add that support.  Otherwise, go with one that supports this already.
75
      </li>
76
    </ul>
77

  
78
    <h2>Issues</h2>
79

  
80
    <h3>Token Expiration</h3>
81

  
82
    <p>
83
      If the total expiration time for your tokens, including successive tokens returned by your token server through refresh tokens (RTs), is less than the maximum time a user can be logged in (see <a href="https://www.drupal.org/project/session_expire">Session Expire</a> for details), users will still be logged in when their final tokens expire.
84
    </p>
85

  
86
    <p>
87
      As this module doesn't (yet) deal with that situation, you'll need to come up with a solution that meets your requirements.  Some background information on this can be found over at <a href="https://rnd.feide.no/2012/04/19/best-practice-for-dealing-with-oauth-2-0-token-expiration-at-the-consumer/">Best-Practice for dealing with OAuth 2.0 Token expiration at the Consumer</a>.
88
    </p>
89

  
90
    <h4>Options</h4>
91

  
92
    <ul>
93
      <li>Automatically log out each user after being logged in for the token expiry time.</li>
94
      <li>Extend the token expiration time to the maximum amount of time a user can be logged in.</li>
95
      <li>Add support for refresh tokens (RTs) that can keep working until a user's login session expires.</li>
96
      <li>Have the token server issue tokens that don't expire.</li>
97
      <li>Some combination of the above.</li>
98
    </ul>
99

  
100
    <h4>Real-World Solutions</h4>
101

  
102
    <ul>
103
      <li><a href="https://developers.facebook.com/docs/facebook-login/access-tokens">Facebook: Access Tokens</a></li>
104
      <li><a href="https://developer.linkedin.com/documents/handling-errors-invalid-tokens">LinkedIn: Handling Errors &amp; Invalid Tokens</a></li>
105
      <li><a href="https://developers.blog.box.com/2013/11/13/oauth2-update-longer-lived-refresh-tokens/">Box: OAuth2 update - Longer lived refresh tokens</a></li>
106
      <li><a href="https://www.salesforce.com/us/developer/docs/api_rest/Content/intro_understanding_refresh_token_oauth.htm">Salesforce: Understanding the OAuth Refresh Token Process</a></li>
107
    </ul>
108

  
109
    <h4>Helpful Drupal Modules</h4>
110

  
111
    <ul>
112
      <li><a href="https://www.drupal.org/project/session_expire">Session expire</a> (also explains the default login session length)</li>
113
      <li><a href="https://www.drupal.org/project/autologout">Automated Logout</a></li>
114
      <li><a href="https://www.drupal.org/project/ejectorseat">Ejector Seat</a></li>
115
    </ul>
116
  </body>
117
</html>
drupal7/sites/all/modules/oauth2_authentication/classes/OAuth2AuthenticationClient.class.php
1
<?php
2

  
3
/**
4
 * @file
5
 * Base class for OAuth2 Authentication clients.
6
 */
7

  
8
/**
9
 * Description of OAuth2AuthenticationClient class.
10
 *
11
 * The OAuth2AuthenticationClient class is used to authenticate users based on
12
 * valid accesss tokens provided by an OAuth2 server.  Once users are logged in,
13
 * their sessions will contain the tokens necessary for gaining access to remote
14
 * resources.  Valid remote users who do not exist locally will be created.
15
 *
16
 * Feel free to subclass in order to override anything done here.  If you do,
17
 * make sure to add the new class to the configuration.
18
 */
19
class OAuth2AuthenticationClient {
20

  
21
  /**
22
   * The username of the user whose access is being requested.
23
   */
24
  protected $username = NULL;
25

  
26
  /**
27
   * The password of the user whose access is being requested.
28
   */
29
  protected $password = NULL;
30

  
31
  /**
32
   * Construct an OAuth2\OAuth2AuthenticationClient object.
33
   *
34
   * @param string $username
35
   *   The username of the user whose authentication is requested.
36
   * @param string $password
37
   *   The username of the user whose authentication is requested.
38
   */
39
  public function __construct($username, $password) {
40
    // Set the username and password for later use.
41
    $this->username = $username;
42
    $this->password = $password;
43
  }
44

  
45
  /**
46
   * Determines if a user with a provided name and password exists remotely.
47
   *
48
   * @return
49
   *   TRUE if the user exists remotely; FALSE otherwise.
50
   */
51
  public function userExistsRemotely() {
52
    // If we can get an access token for this user, then we know he/she exists
53
    // remotely.
54
    return $this->getAccessToken();
55
  }
56

  
57
  /**
58
   * Attempts to get an access token.
59
   *
60
   * @return
61
   *   TRUE if an access token was retrieved; FALSE otherwise.
62
   */
63
  public function getAccessToken() {
64

  
65
    // Configure the OAuth2 client.
66
    $oauth2_config = array(
67
      'auth_flow'      => 'user-password',
68
      'token_endpoint' => variable_get('oauth2_authentication_token_endpoint', ''),
69
      'client_id'      => variable_get('oauth2_authentication_client_id', ''),
70
      'client_secret'  => variable_get('oauth2_authentication_client_secret', ''),
71
      'scope'          => variable_get('oauth2_authentication_scope', ''),
72
      'username'       => $this->username,
73
      'password'       => $this->password,
74
    );
75

  
76
    try {
77
      // Create an OAuth2 client and attempt to get an access token.  If we
78
      // aren't able to, we'll end up in the catch stanza as an exception will
79
      // be thrown.
80
      $oauth2_client = new OAuth2\Client($oauth2_config);
81
      $token = $oauth2_client->getAccessToken();
82
      $token_retrieved = isset($token);
83
    }
84
    catch (Exception $e) {
85
      // We couildn't get an access token for this user so it must not be valid.
86
      $token_retrieved = FALSE;
87
    }
88

  
89
    // Report status in the log.
90
    watchdog('oauth2_authentication', 'Access token requested for user %name: !result', array(
91
      '%name' => $this->username,
92
      '!result' => $token_retrieved ? 'SUCCESS' : 'FAILURE',
93
    ));
94

  
95
    // Return the result.
96
    return $token_retrieved;
97
  }
98

  
99
  /**
100
   * Create a new user based on the successful validation of a remote user.
101
   *
102
   * This function creates a new local Drupal user if a corresponding remote
103
   * user exists, but doesn't exist here yet.
104
   *
105
   * @return
106
   *   A fully-loaded $user object upon successful creation or FALSE on failure.
107
   */
108
  public function createUserLocally() {
109

  
110
    // Get the user's e-mail address from some remote service.
111
    $email = $this->getUserEmailAddress();
112

  
113
    // Create a list of user information.
114
    $user = array(
115
      'name'   => $this->username,
116
      'pass'   => $this->password,
117
      'mail'   => $email,
118
      'status' => 1,
119
      'init'   => $email,
120
      'roles'  => array(
121
        DRUPAL_AUTHENTICATED_RID => 'authenticated user',
122
      ),
123
    );
124

  
125
    // Save the new user.
126
    $user = user_save(NULL, $user);
127

  
128
    // Report the new user in the log.
129
    watchdog('oauth2_authentication', 'New user: %name (%email).', array(
130
      '%name' => $this->username,
131
      '%email' => $email ? $email : 'no e-mail address',
132
    ), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $user->uid . '/edit'));
133

  
134
    // Return it.
135
    return $user;
136
  }
137

  
138
  /*
139
   * Update a user based on the successful validation of a remote user.
140
   *
141
   * This function updates an existing local Drupal user if a corresponding
142
   * remote user exists.
143
   *
144
   * A typical use case for this is when a user's password has changed in the
145
   * OAuth2 provider system but the local Drupal user has an old password entry
146
   * in the users table.
147
   *
148
   * @param $account
149
   *   The user object to be updated.
150
   *
151
   * @return
152
   *   A fully-loaded $user object upon successful update or FALSE on failure.
153
   */
154
  public function updateUserLocally($account) {
155
    // Create a list of user information.
156
    $user = array(
157
      'pass'   => $this->password,
158
      'status' => 1,
159
      'roles'  => array(
160
        DRUPAL_AUTHENTICATED_RID => 'authenticated user',
161
      ),
162
    );
163

  
164
    // Update the account with the new information.
165
    $account = user_save($account, $user);
166

  
167
    // Report the updated user in the log.
168
    watchdog('oauth2_authentication', 'Updated user: %name.', array(
169
      '%name' => $this->username,
170
    ), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));
171

  
172
    return $account;
173
  }
174

  
175
  /**
176
   * Fetches the e-mail address of the user to be created.
177
   *
178
   * This should be overridden.  Otherwise, your users won't have e-mail
179
   * addresses.
180
   *
181
   * @return
182
   *   The user's e-mail address.
183
   */
184
  protected function getUserEmailAddress() {
185
    return '';
186
  }
187

  
188
}
189

  
drupal7/sites/all/modules/oauth2_authentication/includes/oauth2_authentication.admin.inc
1
<?php
2
/**
3
 * @file
4
 * Administrative UI and functions for the OAuth2 Authentication module.
5
 */
6

  
7
/**
8
 * Form builder: Main administrative form.
9
 */
10
function oauth2_authentication_admin_form($form, &$form_state) {
11

  
12
  // Define the set of fields for the server settings.
13
  $form['server'] = array(
14
    '#type' => 'fieldset',
15
    '#title' => t('Server settings'),
16
    '#tree' => TRUE,
17
    '#weight' => 0,
18
    '#collapsible' => TRUE,
19
    '#collapsed' => FALSE,
20
  );
21

  
22
  // Add a text field for the token endpoint.
23
  $form['server']['token_endpoint'] = array(
24
    '#title' => t('Token endpoint URL'),
25
    '#type' => 'textfield',
26
    '#required' => TRUE,
27
    '#default_value' => variable_get('oauth2_authentication_token_endpoint', 'https://idp.example.com/token'),
28
    '#description' => t('A valid URL from where access tokens can be retrieved.'),
29
  );
30

  
31
  // Add a text field for the client ID.
32
  $form['server']['client_id'] = array(
33
    '#title' => t('Client ID'),
34
    '#type' => 'textfield',
35
    '#required' => TRUE,
36
    '#default_value' => variable_get('oauth2_authentication_client_id', ''),
37
    '#description' => t('This sites\'s ID for authenticating to the token server.'),
38
  );
39

  
40
  // Add a text field for the client secret.
41
  $form['server']['client_secret'] = array(
42
    '#title' => t('Client secret'),
43
    '#type' => 'textfield',
44
    '#required' => TRUE,
45
    '#default_value' => variable_get('oauth2_authentication_client_secret', ''),
46
    '#description' => t('This site\'s secret used for authenticating to the token server.'),
47
  );
48

  
49
  // Add a text field for the scope.
50
  $form['server']['scope'] = array(
51
    '#title' => t('Scope'),
52
    '#type' => 'textfield',
53
    '#default_value' => variable_get('oauth2_authentication_scope', ''),
54
    '#description' => t('The scope of the access request.'),
55
  );
56

  
57
  // Define the set of fields for the server settings.
58
  $form['user'] = array(
59
    '#type' => 'fieldset',
60
    '#title' => t('User settings'),
61
    '#tree' => TRUE,
62
    '#description' => t('By default, users will not be allowed to edit their passwords or e-mail addresses as these will normally be handled by a separate CRM-type system.  If you\'d like to make these fields user-editable, you may do so, but be warned that changes within Drupal will not be automatically sent to the other system.'),
63
    '#weight' => 10,
64
    '#collapsible' => TRUE,
65
    '#collapsed' => FALSE,
66
  );
67

  
68
  $form['user']['edit_email'] = array(
69
    '#type' => 'checkbox',
70
    '#title' => t('Allow users to edit their e-mail addresses'),
71
    '#default_value' => variable_get('oauth2_authentication_user_edit_email', FALSE),
72
  );
73

  
74
  $form['user']['edit_password'] = array(
75
    '#type' => 'checkbox',
76
    '#title' => t('Allow users to change their passwords'),
77
    '#default_value' => variable_get('oauth2_authentication_user_edit_password', FALSE),
78
  );
79

  
80
  // Define the set of fields for miscellaneous settings.
81
  $form['misc'] = array(
82
    '#type' => 'fieldset',
83
    '#title' => t('Miscellaneous settings'),
84
    '#tree' => TRUE,
85
    '#description' => t('These settings don\'t fit into any of the other major categories.'),
86
    '#weight' => 20,
87
    '#collapsible' => TRUE,
88
    '#collapsed' => FALSE,
89
  );
90

  
91
  // Add a text field for the name of the class to handle the authentication.
92
  $form['misc']['class'] = array(
93
    '#title' => t('Client class'),
94
    '#type' => 'textfield',
95
    '#required' => TRUE,
96
    '#default_value' => variable_get('oauth2_authentication_class', 'OAuth2AuthenticationClient'),
97
    '#description' => t('The name of the class that handles the authentication.  If you have extended the default one to make modifications, enter it here.'),
98
  );
99

  
100
  // Configure the form submission button.
101
  $form['actions']['#type'] = 'actions';
102
  $form['actions']['submit'] = array(
103
    '#type' => 'submit',
104
    '#value' => t('Save configuration'),
105
    '#weight' => 30,
106
  );
107

  
108
  return $form;
109
}
110

  
111
/**
112
 * Validation handler for oauth2_authentication_admin_form.
113
 */
114
function oauth2_authentication_admin_form_validate($form, &$form_state) {
115

  
116
  // Fetch the form values.
117
  $token_endpoint = $form_state['values']['server']['token_endpoint'];
118
  $client_id      = $form_state['values']['server']['client_id'];
119
  $client_secret  = $form_state['values']['server']['client_secret'];
120
  $scope          = $form_state['values']['server']['scope'];
121
  $class          = $form_state['values']['misc']['class'];
122

  
123
  // Ensure that the token endpoint is a valid URL.
124
  if (!valid_url($token_endpoint, TRUE)) {
125
    form_set_error('server][token_endpoint', 'The token endpoint is not a valid URL.');
126
  }
127

  
128
  // Ensure that the class has been defined.
129
  if (!class_exists($class)) {
130
    form_set_error('misc][class', 'The authentication-handling class has not been defined.  It must exist before it can be used.');
131
  }
132
}
133

  
134
/**
135
 * Submit handler for oauth2_authentication_admin_form.
136
 */
137
function oauth2_authentication_admin_form_submit($form, &$form_state) {
138

  
139
  // Fetch the form values.
140
  $token_endpoint = $form_state['values']['server']['token_endpoint'];
141
  $client_id      = $form_state['values']['server']['client_id'];
142
  $client_secret  = $form_state['values']['server']['client_secret'];
143
  $scope          = $form_state['values']['server']['scope'];
144
  $class          = $form_state['values']['misc']['class'];
145
  $edit_email     = $form_state['values']['user']['edit_email'];
146
  $edit_password  = $form_state['values']['user']['edit_password'];
147

  
148
  // Save the token endpoint.
149
  if (!empty($token_endpoint)) {
150
    variable_set('oauth2_authentication_token_endpoint', $token_endpoint);
151
  }
152

  
153
  // Save the client ID.
154
  if (!empty($client_id)) {
155
    variable_set('oauth2_authentication_client_id', $client_id);
156
  }
157

  
158
  // Save the client secret.
159
  if (!empty($client_secret)) {
160
    variable_set('oauth2_authentication_client_secret', $client_secret);
161
  }
162

  
163
  // Save the scope.
164
  if (!empty($scope)) {
165
    variable_set('oauth2_authentication_scope', $scope);
166
  }
167

  
168
  // Save the class.
169
  if (!empty($class)) {
170
    variable_set('oauth2_authentication_class', $class);
171
  }
172

  
173
  // Save the user checkboxes.
174
  variable_set('oauth2_authentication_user_edit_email', $edit_email);
175
  variable_set('oauth2_authentication_user_edit_password', $edit_password);
176

  
177
  // Report status.
178
  drupal_set_message(t('The configuration options have been saved.'));
179
}
drupal7/sites/all/modules/oauth2_authentication/oauth2_authentication.info
1
name = OAuth2 Authentication
2
description = Authenticates Drupal users via OAuth2
3
core = 7.x
4
package = OAuth2
5

  
6
; Configuration page
7
configure = admin/config/services/oauth2-authentication
8

  
9
; Dependencies
10
dependencies[] = oauth2_client
11

  
12
; Classes
13
files[] = classes/OAuth2AuthenticationClient.class.php
14

  
15
; Information added by Drupal.org packaging script on 2015-01-22
16
version = "7.x-1.1"
17
core = "7.x"
18
project = "oauth2_authentication"
19
datestamp = "1421965681"
20

  
drupal7/sites/all/modules/oauth2_authentication/oauth2_authentication.install
1
<?php
2

  
3
/**
4
 * @file
5
 * Installation file for the OAuth2 Authentication module.
6
 */
7

  
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function oauth2_authentication_uninstall() {
12

  
13
  // Delete the configuration.
14
  variable_del('oauth2_authentication_token_endpoint');
15
  variable_del('oauth2_authentication_client_id');
16
  variable_del('oauth2_authentication_client_secret');
17
  variable_del('oauth2_authentication_scope');
18
  variable_del('oauth2_authentication_class');
19
  variable_del('oauth2_authentication_user_edit_email');
20
  variable_del('oauth2_authentication_user_edit_password');
21
}
drupal7/sites/all/modules/oauth2_authentication/oauth2_authentication.module
1
<?php
2
/**
3
 * @file
4
 * Provides functionality for the OAuth2 Authentication module.
5
 */
6

  
7
/****************************************************************************
8
 * Drupal Core Hooks
9
 ****************************************************************************/
10

  
11
/**
12
 * Implements hook_menu().
13
 */
14
function oauth2_authentication_menu() {
15
  $items = array();
16
  $items['admin/config/services/oauth2-authentication'] = array(
17
    'title' => 'OAuth2 Authentication',
18
    'description' => 'Configure OAuth2 Authentication parameters.',
19
    'page callback' => 'drupal_get_form',
20
    'page arguments' => array('oauth2_authentication_admin_form'),
21
    'access arguments' => array('administer oauth2 authentication'),
22
    'file' => 'includes/oauth2_authentication.admin.inc',
23
  );
24
  return $items;
25
}
26

  
27
/**
28
 * Implements hook_permission().
29
 */
30
function oauth2_authentication_permission() {
31
  return array(
32
    'administer oauth2 authentication' => array(
33
      'title' => t('Administer authentication parameters'),
34
      'description' => t('Allows users to set authentication parameters such as the token endpoint and client credentials.'),
35
    ),
36
  );
37
}
38

  
39
/**
40
 * Implements hook_menu_alter().
41
 *
42
 * Alter some core menu functionality to potentially disable some items.
43
 */
44
function oauth2_authentication_menu_alter(&$items) {
45
  global $user, $language;
46

  
47
  // Set the path for password resets.
48
  $path = 'user/password';
49

  
50
  // Restrict the password reset page to user administrators if password editing
51
  // is disabled.
52
  if ((!variable_get('oauth2_authentication_user_edit_password', FALSE)) &&
53
      ($user->uid != 1)) {
54
    $items[$path]['access callback'] = 'user_access';
55
    $items[$path]['access arguments'] = array('administer users');
56

  
57
    // Add support for language-prefixed paths.  There doesn't appear to be an
58
    // easy way to get them so let's use global variables to do so.
59
    if (($language->language != LANGUAGE_NONE) && (!empty($language->prefix))) {
60
      $prefix = $language->prefix;
61
      $items[$prefix . '/' . $path]['access callback'] = 'user_access';
62
      $items[$prefix . '/' . $path]['access arguments'] = array('administer users');
63
    }
64
  }
65
}
66

  
67
/**
68
 * Implements hook_form_FORM_ID_alter() for the user_login form.
69
 *
70
 * As per user_login_default_validators(), there are three (3) standard
71
 * validation functions that determine if a user can be logged in.
72
 *
73
 *   1. user_login_name_validate()
74
 *   2. user_login_authenticate_validate()
75
 *   3. user_login_final_validate()
76
 *
77
 * We need to override the second one because it determines the user validity
78
 * based exclusively on its existence in the database.  In our case, if the user
79
 * exists as per the remote authorization service, but not locally, we want to
80
 * create it.
81
 */
82
function oauth2_authentication_form_user_login_alter(&$form, &$form_state, $form_id) {
83

  
84
  // Replace the user_login_authenticate_validate() call with our own
85
  // oauth2_authentication_login_authenticate_validate() function.
86
  if (in_array('user_login_authenticate_validate', $form['#validate'])) {
87
    $key = array_search('user_login_authenticate_validate', $form['#validate']);
88
    $form['#validate'][$key] = 'oauth2_authentication_login_authenticate_validate';
89
  }
90
}
91

  
92
/**
93
 * Implements hook_form_FORM_ID_alter() for the user_login_block form.
94
 */
95
function oauth2_authentication_form_user_login_block_alter(&$form, &$form_state, $form_id) {
96
  global $user;
97

  
98
  // Make the same changes as we're making to the standard login form.  See
99
  // oauth2_authentication_form_user_login_alter() for details.
100
  oauth2_authentication_form_user_login_alter($form, $form_state, $form_id);
101

  
102
  // Disable password-reset links if applicable.
103
  if ((!variable_get('oauth2_authentication_user_edit_password', FALSE)) &&
104
      ($user->uid != 1)) {
105
    $form['links'] = '';
106
  }
107
}
108

  
109
/**
110
 * Implements hook_form_FORM_ID_alter() for the user_profile_form form.
111
 *
112
 * Disable editing of externally-controlled user profile fields.  These user
113
 * attributes would normally be controlled by another CRM-type system.  To set
114
 * which fields are to enabled or disabled, go to the module configuration page.
115
 * By default, they are all disabled.
116
 */
117
function oauth2_authentication_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
118
  global $user;
119

  
120
  // We want to keep user fields editable for user administrators so exit if the
121
  // current user is one of them.
122
  if (($user->uid == 1) || user_access('administer users')) {
123
    return;
124
  }
125

  
126
  // Get configuration info on which user attributes are not to be edited.
127
  $disable_email = !variable_get('oauth2_authentication_user_edit_email', FALSE);
128
  $disable_password_change = !variable_get('oauth2_authentication_user_edit_password', FALSE);
129

  
130
  // Disable the current password field if neither the e-mail nor the password
131
  // fields are editable.  It's only needed if one wishes to edit either of
132
  // those fields.
133
  $disable_password_current = ($disable_email && $disable_password_change);
134

  
135
  // Disable editing of the E-mail Address field if was configured as such.
136
  if ($disable_email) {
137
    $form['account']['mail']['#disabled'] = TRUE;
138
  }
139

  
140
  // Disable editing of the Password & Confirm Password fields if they were
141
  // configured as such.
142
  if ($disable_password_change) {
143
    $form['account']['pass']['#disabled'] = TRUE;
144
  }
145

  
146
  // Disable editing of the Current Password field if was configured as such.
147
  if ($disable_password_current) {
148
    $form['account']['current_pass']['#disabled'] = TRUE;
149
  }
150
}
151

  
152
/**
153
 * Implements hook_user_logout().
154
 *
155
 * Purge any access tokens stored in the user's session.  We definitely don't
156
 * want these to be used by a different user that logs in sometime between now
157
 * and the existing token's expiration time.
158
 */
159
function oauth2_authentication_user_logout($account) {
160

  
161
  // As using unset() on a global variable may not always unset it outside of
162
  // the current scope, simply drop any OAuth2 tokens by assigning an empty
163
  // list.
164
  $_SESSION['oauth2_client'] = array();
165
}
166

  
167
/****************************************************************************
168
 * Drupal Core Function Replacements
169
 ****************************************************************************/
170

  
171
/**
172
 * Replacement for user_login_authenticate_validate().
173
 *
174
 * All code here except for the last stanza should be identical to what's in
175
 * user_login_authenticate_validate().  The last stanza is the only thing we'd
176
 * like to change as that's the function call we actually care about.
177
 */
178
function oauth2_authentication_login_authenticate_validate($form, &$form_state) {
179
  $password = trim($form_state['values']['pass']);
180
  if (!empty($form_state['values']['name']) && !empty($password)) {
181
    // Do not allow any login from the current user's IP if the limit has been
182
    // reached. Default is 50 failed attempts allowed in one hour. This is
183
    // independent of the per-user limit to catch attempts from one IP to log
184
    // in to many different user accounts.  We have a reasonably high limit
185
    // since there may be only one apparent IP for all users at an institution.
186
    if (!flood_is_allowed('failed_login_attempt_ip', variable_get('user_failed_login_ip_limit', 50), variable_get('user_failed_login_ip_window', 3600))) {
187
      $form_state['flood_control_triggered'] = 'ip';
188
      return;
189
    }
190
    $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
191
    if ($account) {
192
      if (variable_get('user_failed_login_identifier_uid_only', FALSE)) {
193
        // Register flood events based on the uid only, so they apply for any
194
        // IP address. This is the most secure option.
195
        $identifier = $account->uid;
196
      }
197
      else {
198
        // The default identifier is a combination of uid and IP address. This
199
        // is less secure but more resistant to denial-of-service attacks that
200
        // could lock out all users with public user names.
201
        $identifier = $account->uid . '-' . ip_address();
202
      }
203
      $form_state['flood_control_user_identifier'] = $identifier;
204

  
205
      // Don't allow login if the limit for this user has been reached.
206
      // Default is to allow 5 failed attempts every 6 hours.
207
      if (!flood_is_allowed('failed_login_attempt_user', variable_get('user_failed_login_user_limit', 5), variable_get('user_failed_login_user_window', 21600), $identifier)) {
208
        $form_state['flood_control_triggered'] = 'user';
209
        return;
210
      }
211
    }
212

  
213
    // We are not limited by flood control, so try to authenticate.
214
    // Set $form_state['uid'] as a flag for user_login_final_validate().
215
    $form_state['uid'] = oauth2_authentication_authenticate($form_state['values']['name'], $password);
216
  }
217
}
218

  
219
/**
220
 * Replacement for user_authenticate().
221
 *
222
 * user_authenticate() determines if a user is valid by looking it up in the
223
 * local database.  If that's not the case, the user may exist in the remote
224
 * system.  So we want to add him/her locally if he/she exists there.  If the
225
 * user does exist locally, we'd like to add a token to his/her session.
226
 *
227
 * @param $name
228
 *   User name to authenticate.
229
 * @param $password
230
 *   A plain-text password, such as trimmed text from form values.
231
 * @return
232
 *   The user's uid on success, or FALSE on failure to authenticate.
233
 */
234
function oauth2_authentication_authenticate($name, $password) {
235

  
236
  // Assume the user is invalid until we determine otherwise.
237
  $uid = FALSE;
238

  
239
  // Only check for a valid user if the username & password were set.
240
  if (!empty($name) && !empty($password)) {
241

  
242
    // Attempt to load a local user with that name.
243
    $account = user_load_by_name($name);
244

  
245
    // Instantiate an OAuth2 Authentication class with the credentials.
246
    $class = variable_get('oauth2_authentication_class', 'OAuth2AuthenticationClient');
247
    $client = new $class($name, $password);
248

  
249
    // If the load was successful, we can see if the entered password is valid.
250
    if ($account) {
251

  
252
      // Allow alternate password hashing schemes in checking the password.
253
      require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
254
      if (user_check_password($password, $account)) {
255

  
256
        // Successful authentication.
257
        $uid = $account->uid;
258

  
259
        // Update user to new password scheme if needed.
260
        if (user_needs_new_hash($account)) {
261
          user_save($account, array('pass' => $password));
262
        }
263

  
264
        // Get a remote access token if possible.  If it's not possible, the
265
        // user can still log in, but he/she won't be able to access remote
266
        // resources.
267
        $client->getAccessToken();
268
      } else {
269
        // Maybe the remote password has changed and the user is trying new password.
270

  
271
        // Check if the user exists remotely.  If so update their account/password.
272
        if ($client->userExistsRemotely()) {
273
          $uid = $client->updateUserLocally($account)->uid;
274
        }
275
      }
276
    }
277

  
278
    else /* there is no local user account */ {
279

  
280
      // Instantiate an OAuth2 Authentication class with the credentials.
281
      $class = variable_get('oauth2_authentication_class', 'OAuth2AuthenticationClient');
282
      $client = new $class($name, $password);
283

  
284
      // Check if the user exists remotely.
285
      if ($client->userExistsRemotely()) {
286

  
287
        // We're dealing with a valid remote user so create it locally.
288
        $uid = $client->createUserLocally()->uid;
289
      }
290
    }
291
  }
292

  
293
  // Return the user's local ID if there is one.
294
  return $uid;
295
}
296

  
drupal7/sites/all/modules/oauth2_client/LICENSE.txt
1
                    GNU GENERAL PUBLIC LICENSE
2
                       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
                            Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Lesser General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

  
59
                    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

  
114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

  
172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

  
229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
                            NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
                     END OF TERMS AND CONDITIONS
281

  
282
            How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff