Add M365 Login plugin: Microsoft Entra ID sign-in for existing users
Adds a WordPress plugin that places a customisable "Sign in with Microsoft" button on wp-login.php and signs existing users in via the OpenID Connect authorization code flow with PKCE. Users are matched by e-mail address only; no accounts are created. Security: single-use state/nonce bound to an HttpOnly cookie, ID token signature verification against Microsoft's JWKS (RS256 only) with issuer/audience/tenant/expiry/nonce checks, optional tenant pinning, account binding to the Microsoft object ID, e-mail domain allow-list, client secret encrypted at rest (AES-256-GCM). Admin: settings screen with connection, button and security tabs, live button preview, colour presets, media-library icon picker, redirect URI copy button and tenant connectivity test. Packaging for WordPress.org: readme.txt with External services section, GPL-2.0 license, uninstall.php, POT + German translations, .distignore, build script, PHPCS config and CI running Plugin Check. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJxAHYdMfKPoN4koRc4Ci2
This commit is contained in:
commit
3e3e87b399
35 changed files with 5413 additions and 0 deletions
20
.distignore
Normal file
20
.distignore
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Files excluded from the distributable ZIP / SVN trunk.
|
||||
.git
|
||||
.github
|
||||
.gitattributes
|
||||
.gitignore
|
||||
.distignore
|
||||
.editorconfig
|
||||
.wordpress-org
|
||||
bin
|
||||
docs
|
||||
node_modules
|
||||
vendor
|
||||
tests
|
||||
composer.json
|
||||
composer.lock
|
||||
phpcs.xml.dist
|
||||
phpunit.xml.dist
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
*.zip
|
||||
15
.editorconfig
Normal file
15
.editorconfig
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
||||
|
||||
[*.{md,yml,yaml,json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.txt]
|
||||
trim_trailing_whitespace = false
|
||||
22
.gitattributes
vendored
Normal file
22
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Keep the GitHub archive identical to the wp.org distribution.
|
||||
.git* export-ignore
|
||||
.github export-ignore
|
||||
.distignore export-ignore
|
||||
.editorconfig export-ignore
|
||||
.wordpress-org export-ignore
|
||||
bin export-ignore
|
||||
docs export-ignore
|
||||
composer.json export-ignore
|
||||
composer.lock export-ignore
|
||||
phpcs.xml.dist export-ignore
|
||||
README.md export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
|
||||
*.php text eol=lf
|
||||
*.css text eol=lf
|
||||
*.js text eol=lf
|
||||
*.txt text eol=lf
|
||||
*.md text eol=lf
|
||||
*.po text eol=lf
|
||||
*.pot text eol=lf
|
||||
*.mo binary
|
||||
51
.github/workflows/ci.yml
vendored
Normal file
51
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: PHP lint (${{ matrix.php }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
- name: Syntax check
|
||||
run: find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l
|
||||
|
||||
phpcs:
|
||||
name: WordPress Coding Standards
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
coverage: none
|
||||
tools: composer
|
||||
- name: Install dev dependencies
|
||||
run: composer install --no-interaction --prefer-dist
|
||||
- name: Run PHPCS
|
||||
run: vendor/bin/phpcs --report=checkstyle | cs2pr || vendor/bin/phpcs
|
||||
|
||||
plugin-check:
|
||||
name: WordPress.org Plugin Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build distributable
|
||||
run: bash bin/build-zip.sh
|
||||
- name: Run Plugin Check
|
||||
uses: wordpress/plugin-check-action@v1
|
||||
with:
|
||||
build-dir: ./build/m365-login
|
||||
exclude-directories: ''
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/vendor/
|
||||
/node_modules/
|
||||
/build/
|
||||
/dist/
|
||||
*.zip
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
.phpcs-cache
|
||||
12
.wordpress-org/README.md
Normal file
12
.wordpress-org/README.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# WordPress.org assets
|
||||
|
||||
Files in this folder are **not** shipped with the plugin. They are uploaded to the
|
||||
`assets/` directory of the WordPress.org SVN repository once the plugin is approved:
|
||||
|
||||
| File | Purpose | Size |
|
||||
| --- | --- | --- |
|
||||
| `icon.svg` | Plugin icon (directory + plugin installer) | vector, or `icon-128x128.png` / `icon-256x256.png` |
|
||||
| `banner-772x250.png` | Directory page header (not included yet) | 772×250 (+ `banner-1544x500.png` for HiDPI) |
|
||||
| `screenshot-1.png` … | Screenshots referenced from `readme.txt` | any, PNG/JPG |
|
||||
|
||||
Screenshot order must match the `== Screenshots ==` section in `readme.txt`.
|
||||
16
.wordpress-org/icon.svg
Normal file
16
.wordpress-org/icon.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="256" height="256">
|
||||
<rect width="256" height="256" rx="48" fill="#1b1b1f"/>
|
||||
<g transform="translate(58 58)">
|
||||
<rect x="0" y="0" width="66" height="66" rx="6" fill="#f25022"/>
|
||||
<rect x="74" y="0" width="66" height="66" rx="6" fill="#7fba00"/>
|
||||
<rect x="0" y="74" width="66" height="66" rx="6" fill="#00a4ef"/>
|
||||
<rect x="74" y="74" width="66" height="66" rx="6" fill="#ffb900"/>
|
||||
</g>
|
||||
<g transform="translate(150 150)">
|
||||
<circle cx="36" cy="36" r="44" fill="#1b1b1f"/>
|
||||
<circle cx="36" cy="36" r="36" fill="#0078d4"/>
|
||||
<path d="M24 34v-6a12 12 0 0 1 24 0v6" fill="none" stroke="#fff" stroke-width="5" stroke-linecap="round"/>
|
||||
<rect x="18" y="33" width="36" height="24" rx="5" fill="#fff"/>
|
||||
<circle cx="36" cy="44" r="3.5" fill="#0078d4"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 855 B |
17
CHANGELOG.md
Normal file
17
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project are documented in this file. The format follows
|
||||
[Keep a Changelog](https://keepachangelog.com/) and the plugin adheres to
|
||||
[Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [1.0.0] – 2026-09-22
|
||||
|
||||
### Added
|
||||
- "Sign in with Microsoft" button on `wp-login.php` (OpenID Connect authorization code flow with PKCE).
|
||||
- Matching of existing WordPress users by e-mail address (optional UPN fallback), no user provisioning.
|
||||
- Settings screen (Settings → M365 Login) with connection, button and security tabs, live button preview, colour presets, media-library icon picker, redirect-URI copy button and tenant connectivity test.
|
||||
- ID token verification against Microsoft's JWKS (RS256, issuer, audience, tenant, expiry, nonce).
|
||||
- Encrypted client secret storage (AES-256-GCM).
|
||||
- Account binding to the Microsoft object ID, e-mail domain allow-list.
|
||||
- `[m365_login_button]` shortcode and developer hooks.
|
||||
- German translation.
|
||||
339
LICENSE
Normal file
339
LICENSE
Normal file
|
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
94
README.md
Normal file
94
README.md
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# M365 Login für WordPress
|
||||
|
||||
Ein schlankes, sicherheitsorientiertes WordPress-Plugin, das einen **„Login mit Microsoft“-Button** auf die
|
||||
Anmeldeseite (`wp-login.php`) setzt. Bestehende WordPress-Benutzer melden sich mit ihrem Microsoft 365 /
|
||||
Entra-ID-Konto an. Der gemeinsame Schlüssel ist die **E-Mail-Adresse** – es werden keine Benutzer angelegt.
|
||||
|
||||
> Plugin-Slug / Text Domain: `m365-login` · Lizenz: GPL-2.0-or-later · PHP ≥ 7.4 · WordPress ≥ 6.0
|
||||
|
||||
## Funktionen
|
||||
|
||||
- **Button auf der Login-Seite** – Text, Icon (Microsoft-Logo oder eigenes Bild aus der Mediathek), Hintergrund-,
|
||||
Hover-, Text- und Rahmenfarbe, Eckenradius und Position (über/unter dem Formular) sind im Backend einstellbar,
|
||||
mit Live-Vorschau und Farb-Presets.
|
||||
- **Aufgeräumte Einstellungsseite** unter *Einstellungen → M365 Login* mit Redirect-URI zum Kopieren,
|
||||
Tenant-Verbindungstest und 5-Schritte-Anleitung.
|
||||
- **Kein Provisioning**: Anmeldung nur, wenn ein WordPress-Benutzer mit derselben E-Mail-Adresse existiert.
|
||||
- **Shortcode** `[m365_login_button redirect="/mein-konto/"]` für eigene Login-Seiten.
|
||||
- Vollständig übersetzbar, deutsche Übersetzung enthalten.
|
||||
|
||||
## Sicherheit
|
||||
|
||||
| Maßnahme | Umsetzung |
|
||||
| --- | --- |
|
||||
| Authorization Code Flow **mit PKCE (S256)** | Tokens laufen ausschließlich Server-zu-Server, nie durch den Browser. |
|
||||
| **State & Nonce** | Einmalig, 10 Minuten gültig, per HttpOnly/SameSite-Cookie an den Browser gebunden (CSRF-/Replay-Schutz, verhindert Login-CSRF). |
|
||||
| **ID-Token-Prüfung** | Signatur gegen Microsofts JWKS (RS256, Schlüssel-Rollover wird abgefangen), Issuer, Audience, Tenant, `exp`/`nbf`/`iat`, Nonce. `alg=none`/HMAC werden abgelehnt. |
|
||||
| **Tenant-Pinning** | Bei konfigurierter Tenant-GUID werden Tokens anderer Tenants abgewiesen. |
|
||||
| **Konto-Bindung** | Beim ersten Login wird die unveränderliche Microsoft-Objekt-ID am Benutzer gespeichert; spätere Logins mit gleicher E-Mail, aber anderer Identität werden abgelehnt. |
|
||||
| **Domain-Allowlist** | Optional nur bestimmte E-Mail-Domains zulassen. |
|
||||
| **Client Secret verschlüsselt** | AES-256-GCM, Schlüssel aus den WordPress-Salts abgeleitet; wird nie wieder angezeigt. |
|
||||
| **WordPress-Standards** | Capability-Checks, Nonces, Sanitizing aller Eingaben, Escaping aller Ausgaben, `wp_safe_redirect`, keine externen Assets. |
|
||||
|
||||
## Installation & Einrichtung
|
||||
|
||||
1. Ordner in `wp-content/plugins/` legen (oder ZIP aus `bin/build-zip.sh` hochladen) und aktivieren.
|
||||
2. *Einstellungen → M365 Login* öffnen und die **Redirect-URI** aus der Seitenleiste kopieren
|
||||
(`https://deine-seite.tld/m365-login/callback`).
|
||||
3. Im [Microsoft Entra Admin Center](https://entra.microsoft.com/) → **App-Registrierungen → Neue Registrierung**:
|
||||
- Name frei wählbar, z. B. „WordPress Login“.
|
||||
- Kontotypen: *Nur Konten in diesem Organisationsverzeichnis* (Single Tenant).
|
||||
- Plattform **Web**, Redirect-URI einfügen.
|
||||
4. Auf der Übersichtsseite **Anwendungs-ID (Client)** und **Verzeichnis-ID (Mandant)** kopieren und im Plugin eintragen.
|
||||
5. **Zertifikate & Geheimnisse → Neuer geheimer Clientschlüssel** – den *Wert* (nicht die ID) ins Plugin eintragen.
|
||||
Ablaufdatum notieren; abgelaufene Secrets müssen erneuert werden.
|
||||
6. **Tokenkonfiguration → Optionalen Anspruch hinzufügen → ID → `email`** (empfohlen). Die delegierten
|
||||
Berechtigungen `openid`, `profile`, `email` sind standardmäßig vorhanden.
|
||||
7. Speichern. Der Button erscheint auf `wp-login.php`; Gestaltung im Tab **Button**.
|
||||
|
||||
Stelle sicher, dass die E-Mail-Adressen der WordPress-Benutzer mit denen in Microsoft 365 übereinstimmen.
|
||||
|
||||
## Entwickler-Hooks
|
||||
|
||||
```php
|
||||
// Button z. B. nur für eine bestimmte Domain anzeigen
|
||||
add_filter( 'm365_login_show_button', fn( $show ) => $show && 'intranet.example.com' === $_SERVER['HTTP_HOST'] );
|
||||
|
||||
// domain_hint an Microsoft senden
|
||||
add_filter( 'm365_login_authorize_params', function ( $params ) {
|
||||
$params['domain_hint'] = 'contoso.com';
|
||||
return $params;
|
||||
} );
|
||||
|
||||
// Login zusätzlich anhand der Claims verbieten (z. B. Gruppenmitgliedschaft)
|
||||
add_filter( 'm365_login_allow_user', function ( $allowed, WP_User $user, array $claims ) {
|
||||
return $allowed && ! empty( $claims['groups'] );
|
||||
}, 10, 3 );
|
||||
|
||||
add_action( 'm365_login_success', function ( WP_User $user, array $claims ) {
|
||||
// z. B. Anzeigenamen synchronisieren
|
||||
}, 10, 2 );
|
||||
```
|
||||
|
||||
Weitere: `m365_login_match_email` (E-Mail vor dem Lookup anpassen).
|
||||
|
||||
## Entwicklung
|
||||
|
||||
```bash
|
||||
composer install # PHPCS + WordPress Coding Standards
|
||||
composer lint # php -l über alle Dateien
|
||||
composer phpcs # Coding-Standards-Prüfung
|
||||
bash bin/build-zip.sh # build/m365-login.zip für Upload/Einreichung
|
||||
python3 bin/compile-mo.py # languages/*.po → *.mo
|
||||
```
|
||||
|
||||
Die GitHub-Actions-Pipeline (`.github/workflows/ci.yml`) führt Syntax-Check (PHP 7.4–8.4), PHPCS und den
|
||||
offiziellen **WordPress Plugin Check** aus.
|
||||
|
||||
## Einreichung bei WordPress.org
|
||||
|
||||
Siehe [docs/wordpress-org-einreichung.md](docs/wordpress-org-einreichung.md) für die vollständige Checkliste.
|
||||
|
||||
## Lizenz
|
||||
|
||||
GPL-2.0-or-later – siehe [LICENSE](LICENSE).
|
||||
578
assets/css/admin.css
Normal file
578
assets/css/admin.css
Normal file
|
|
@ -0,0 +1,578 @@
|
|||
/* M365 Login – settings screen */
|
||||
.m365-admin {
|
||||
--m365-accent: #0078d4;
|
||||
--m365-accent-dark: #106ebe;
|
||||
--m365-border: #dcdcde;
|
||||
--m365-muted: #646970;
|
||||
--m365-radius: 10px;
|
||||
max-width: 1180px;
|
||||
}
|
||||
|
||||
.m365-admin h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
margin: 0 0 4px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.m365-admin__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
margin: 12px 0 20px;
|
||||
}
|
||||
|
||||
.m365-admin__brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.m365-admin__brand p {
|
||||
margin: 0;
|
||||
color: var(--m365-muted);
|
||||
}
|
||||
|
||||
.m365-admin__logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.m365-admin__logo svg {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.m365-admin__status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 12px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
background: #fcf0e4;
|
||||
color: #8a4b00;
|
||||
}
|
||||
|
||||
.m365-admin__status.is-ok {
|
||||
background: #e6f4ea;
|
||||
color: #1e6b31;
|
||||
}
|
||||
|
||||
.m365-admin__status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.m365-admin__tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
border-bottom: 1px solid var(--m365-border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.m365-admin__tab {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-bottom: 2px solid transparent;
|
||||
margin-bottom: -1px;
|
||||
padding: 10px 14px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--m365-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.m365-admin__tab:hover {
|
||||
color: #1d2327;
|
||||
}
|
||||
|
||||
.m365-admin__tab.is-active {
|
||||
color: var(--m365-accent);
|
||||
border-bottom-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
.m365-admin__tab:focus-visible {
|
||||
outline: 2px solid var(--m365-accent);
|
||||
outline-offset: -2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.m365-admin__panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-admin__panel.is-active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.m365-admin__layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 340px;
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.m365-admin__layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.m365-admin__actions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.m365-card {
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
padding: 24px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
.m365-card--accent {
|
||||
border-color: #b6d7f2;
|
||||
background: linear-gradient(180deg, #f3f9fe 0%, #fff 100%);
|
||||
}
|
||||
|
||||
.m365-card--muted {
|
||||
background: #f6f7f7;
|
||||
}
|
||||
|
||||
.m365-card__title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.m365-card__intro {
|
||||
margin: 0 0 20px;
|
||||
color: var(--m365-muted);
|
||||
}
|
||||
|
||||
/* Fields */
|
||||
.m365-field {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.m365-field:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.m365-field > label,
|
||||
.m365-field__label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.m365-field input[type="text"],
|
||||
.m365-field input[type="url"],
|
||||
.m365-field input[type="password"],
|
||||
.m365-field select,
|
||||
.m365-field textarea {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
border-radius: 6px;
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
.m365-field .regular-text {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m365-field__row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.m365-field__row > input {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.m365-field__row .button {
|
||||
flex: 0 0 auto;
|
||||
min-height: 36px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.m365-field .description {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.m365-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 20px;
|
||||
}
|
||||
|
||||
.m365-grid--4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.m365-grid,
|
||||
.m365-grid--4 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.m365-check {
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
|
||||
.m365-check--block {
|
||||
display: flex;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
margin: 0 0 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.m365-check--block:hover {
|
||||
border-color: #b6d7f2;
|
||||
background: #fbfdff;
|
||||
}
|
||||
|
||||
.m365-check--block input {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.m365-check--block strong {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.m365-check--block em {
|
||||
display: block;
|
||||
font-style: normal;
|
||||
color: var(--m365-muted);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.m365-inline-result {
|
||||
margin-top: 10px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
background: #f0f6fc;
|
||||
border: 1px solid #c5d9ed;
|
||||
}
|
||||
|
||||
.m365-inline-result.is-success {
|
||||
background: #e6f4ea;
|
||||
border-color: #a6d8b2;
|
||||
}
|
||||
|
||||
.m365-inline-result.is-error {
|
||||
background: #fcf0f1;
|
||||
border-color: #f0b8bd;
|
||||
}
|
||||
|
||||
.m365-inline-result code {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.m365-warning {
|
||||
margin: 12px 0 0;
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
background: #fcf0e4;
|
||||
color: #8a4b00;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.m365-toggle-secret .dashicons {
|
||||
line-height: 1;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.m365-link-danger {
|
||||
color: #b32d2e;
|
||||
}
|
||||
|
||||
/* Preview */
|
||||
.m365-preview {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.m365-preview__label {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--m365-muted);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.m365-preview__stage {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 32px 24px;
|
||||
background: #f0f0f1 radial-gradient(circle at 1px 1px, #dcdcde 1px, transparent 0);
|
||||
background-size: 16px 16px;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.m365-login--preview {
|
||||
width: 272px;
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
padding: 24px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
--m365-bg: #2f2f2f;
|
||||
--m365-bg-hover: #1a1a1a;
|
||||
--m365-color: #fff;
|
||||
--m365-border: #2f2f2f;
|
||||
--m365-radius: 4px;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
margin: 0 0 22px;
|
||||
color: #646970;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
height: 1px;
|
||||
background: #dcdcde;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider span {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__divider.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 10px 16px;
|
||||
background: var(--m365-bg);
|
||||
color: var(--m365-color);
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
transition: background-color 0.15s ease;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button:hover {
|
||||
background: var(--m365-bg-hover);
|
||||
color: var(--m365-color);
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__button:focus {
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__icon,
|
||||
.m365-login--preview #m365-preview-icon img,
|
||||
.m365-login--preview #m365-preview-icon svg {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: block;
|
||||
background: #fff;
|
||||
padding: 3px;
|
||||
box-sizing: content-box;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.m365-login--preview #m365-preview-icon.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.m365-login--preview .m365-login__label {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Icon picker */
|
||||
.m365-icon-picker {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__thumb {
|
||||
flex: 0 0 64px;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__thumb img,
|
||||
.m365-icon-picker__thumb svg {
|
||||
max-width: 36px;
|
||||
max-height: 36px;
|
||||
}
|
||||
|
||||
.m365-icon-picker__controls {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.m365-icon-picker__controls .m365-field__row {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* Colour pickers */
|
||||
.m365-field .wp-picker-container {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.m365-field .wp-picker-container .wp-color-result.button {
|
||||
margin: 0;
|
||||
min-height: 36px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.m365-range-value {
|
||||
font-weight: 400;
|
||||
color: var(--m365-muted);
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.m365-field input[type="range"] {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
accent-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
/* Presets */
|
||||
.m365-presets {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.m365-presets .m365-field__label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m365-preset {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 12px 6px 8px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.m365-preset:hover {
|
||||
border-color: var(--m365-accent);
|
||||
}
|
||||
|
||||
.m365-preset span {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
.m365-copy {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.m365-copy code {
|
||||
flex: 1 1 auto;
|
||||
padding: 8px 10px;
|
||||
font-size: 12px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: 6px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.m365-copy__button {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.m365-steps {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.m365-steps li {
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.m365-list {
|
||||
margin: 8px 0 0;
|
||||
padding-left: 18px;
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.m365-list li {
|
||||
margin-bottom: 6px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.m365-card code {
|
||||
font-size: 12px;
|
||||
}
|
||||
122
assets/css/login.css
Normal file
122
assets/css/login.css
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* M365 Login – login screen button */
|
||||
.m365-login {
|
||||
--m365-bg: #2f2f2f;
|
||||
--m365-bg-hover: #1a1a1a;
|
||||
--m365-color: #ffffff;
|
||||
--m365-border: #2f2f2f;
|
||||
--m365-radius: 4px;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.m365-login--below {
|
||||
background: #fff;
|
||||
padding: 0 24px 26px;
|
||||
margin: -1px 0 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
border: 1px solid #c3c4c7;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
body.m365-login-attached #loginform {
|
||||
border-bottom: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.m365-login--above {
|
||||
background: #fff;
|
||||
padding: 24px;
|
||||
margin: 20px 0 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
border: 1px solid #c3c4c7;
|
||||
}
|
||||
|
||||
.m365-login--above .m365-login__divider {
|
||||
margin: 22px 0 0;
|
||||
}
|
||||
|
||||
.m365-login__divider {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
margin: 0 0 22px;
|
||||
color: #646970;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.m365-login__divider::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
height: 1px;
|
||||
background: #dcdcde;
|
||||
}
|
||||
|
||||
.m365-login__divider span {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.m365-login__button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
padding: 10px 16px;
|
||||
background: var(--m365-bg);
|
||||
color: var(--m365-color);
|
||||
border: 1px solid var(--m365-border);
|
||||
border-radius: var(--m365-radius);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
|
||||
}
|
||||
|
||||
.m365-login__button:hover,
|
||||
.m365-login__button:focus {
|
||||
background: var(--m365-bg-hover);
|
||||
color: var(--m365-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.m365-login__button:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--m365-bg-hover);
|
||||
}
|
||||
|
||||
.m365-login__button:active {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
.m365-login__icon {
|
||||
flex: 0 0 auto;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: block;
|
||||
background: #fff;
|
||||
padding: 3px;
|
||||
box-sizing: content-box;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.m365-login__label {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.m365-login--shortcode {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
max-width: 360px;
|
||||
}
|
||||
189
assets/js/admin.js
Normal file
189
assets/js/admin.js
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/* global jQuery, wp, m365LoginAdmin */
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
var cfg = window.m365LoginAdmin || {};
|
||||
var i18n = cfg.i18n || {};
|
||||
|
||||
$( function () {
|
||||
var $preview = $( '#m365-preview' );
|
||||
|
||||
/* ---------------- Tabs ---------------- */
|
||||
var $tabs = $( '.m365-admin__tab' );
|
||||
var $panels = $( '.m365-admin__panel' );
|
||||
|
||||
function activate( name ) {
|
||||
$tabs.removeClass( 'is-active' ).attr( 'aria-selected', 'false' ).filter( '[data-tab="' + name + '"]' ).addClass( 'is-active' ).attr( 'aria-selected', 'true' );
|
||||
$panels.removeClass( 'is-active' ).filter( '[data-panel="' + name + '"]' ).addClass( 'is-active' );
|
||||
try {
|
||||
window.localStorage.setItem( 'm365LoginTab', name );
|
||||
} catch ( e ) {}
|
||||
}
|
||||
|
||||
$tabs.on( 'click', function () {
|
||||
activate( $( this ).data( 'tab' ) );
|
||||
} );
|
||||
|
||||
try {
|
||||
var saved = window.localStorage.getItem( 'm365LoginTab' );
|
||||
if ( saved && $tabs.filter( '[data-tab="' + saved + '"]' ).length ) {
|
||||
activate( saved );
|
||||
}
|
||||
} catch ( e ) {}
|
||||
|
||||
// Jump to the tab that contains a validation error.
|
||||
var $error = $( '.settings-error' ).first();
|
||||
if ( $error.length && $error.text().toLowerCase().indexOf( 'tenant' ) !== -1 ) {
|
||||
activate( 'connection' );
|
||||
}
|
||||
|
||||
/* ---------------- Live preview ---------------- */
|
||||
function setVar( name, value ) {
|
||||
$preview[ 0 ].style.setProperty( '--m365-' + name, value );
|
||||
}
|
||||
|
||||
function updateIcon() {
|
||||
var show = $( '[data-preview="show-icon"]' ).is( ':checked' );
|
||||
var url = $.trim( $( '#m365-icon-url' ).val() );
|
||||
var $icon = $( '#m365-preview-icon' );
|
||||
var $thumb = $( '#m365-icon-thumb' );
|
||||
|
||||
$icon.toggleClass( 'is-hidden', ! show );
|
||||
|
||||
if ( url ) {
|
||||
var $img = $( '<img>', { src: url, alt: '' } );
|
||||
$icon.empty().append( $img );
|
||||
$thumb.empty().append( $img.clone() );
|
||||
} else {
|
||||
$icon.html( cfg.defaultLogo || '' );
|
||||
$thumb.html( cfg.defaultLogo || '' );
|
||||
}
|
||||
}
|
||||
|
||||
$( '[data-preview="text"]' ).on( 'input', function () {
|
||||
$( '#m365-preview-text' ).text( $( this ).val() );
|
||||
} );
|
||||
|
||||
$( '[data-preview="divider"]' ).on( 'input', function () {
|
||||
var val = $.trim( $( this ).val() );
|
||||
$( '#m365-preview-divider' ).text( val ).closest( '.m365-login__divider' ).toggleClass( 'is-hidden', ! val );
|
||||
} ).trigger( 'input' );
|
||||
|
||||
$( '[data-preview="show-icon"], #m365-icon-url' ).on( 'change input', updateIcon );
|
||||
|
||||
$( '[data-preview="radius"]' ).on( 'input change', function () {
|
||||
setVar( 'radius', $( this ).val() + 'px' );
|
||||
$( '#m365-radius-value' ).text( $( this ).val() + ' px' );
|
||||
} );
|
||||
|
||||
$( '.m365-color' ).wpColorPicker( {
|
||||
change: function ( event, ui ) {
|
||||
var key = $( event.target ).data( 'preview' );
|
||||
var color = ui.color.toString();
|
||||
setVar( key.replace( '_', '-' ), color );
|
||||
},
|
||||
clear: function ( event ) {
|
||||
var $input = $( event.target ).closest( '.wp-picker-container' ).find( '.m365-color' );
|
||||
setVar( $input.data( 'preview' ).replace( '_', '-' ), $input.data( 'default-color' ) );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.m365-preset' ).on( 'click', function () {
|
||||
var preset = $( this ).data( 'preset' );
|
||||
if ( ! preset ) {
|
||||
return;
|
||||
}
|
||||
$.each( preset, function ( key, value ) {
|
||||
$( '#m365-button_' + key ).wpColorPicker( 'color', value );
|
||||
} );
|
||||
} );
|
||||
|
||||
/* ---------------- Media library ---------------- */
|
||||
var frame;
|
||||
$( '#m365-icon-choose' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
if ( ! window.wp || ! wp.media ) {
|
||||
return;
|
||||
}
|
||||
if ( ! frame ) {
|
||||
frame = wp.media( {
|
||||
title: i18n.chooseIcon || '',
|
||||
button: { text: i18n.useIcon || '' },
|
||||
library: { type: 'image' },
|
||||
multiple: false
|
||||
} );
|
||||
frame.on( 'select', function () {
|
||||
var attachment = frame.state().get( 'selection' ).first().toJSON();
|
||||
var url = attachment.url;
|
||||
if ( attachment.sizes && attachment.sizes.thumbnail && attachment.mime !== 'image/svg+xml' ) {
|
||||
url = attachment.sizes.thumbnail.url;
|
||||
}
|
||||
$( '#m365-icon-url' ).val( url ).trigger( 'input' );
|
||||
} );
|
||||
}
|
||||
frame.open();
|
||||
} );
|
||||
|
||||
$( '#m365-icon-reset' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
$( '#m365-icon-url' ).val( '' ).trigger( 'input' );
|
||||
} );
|
||||
|
||||
/* ---------------- Secret visibility ---------------- */
|
||||
$( '.m365-toggle-secret' ).on( 'click', function () {
|
||||
var $input = $( '#m365-client-secret' );
|
||||
var show = 'password' === $input.attr( 'type' );
|
||||
$input.attr( 'type', show ? 'text' : 'password' );
|
||||
$( this ).find( '.dashicons' ).toggleClass( 'dashicons-visibility', ! show ).toggleClass( 'dashicons-hidden', show );
|
||||
} );
|
||||
|
||||
/* ---------------- Copy redirect URI ---------------- */
|
||||
$( '.m365-copy__button' ).on( 'click', function () {
|
||||
var $btn = $( this );
|
||||
var text = $( '#' + $btn.data( 'copy' ) ).text();
|
||||
var done = function () {
|
||||
$btn.text( i18n.copied || 'Copied!' );
|
||||
window.setTimeout( function () {
|
||||
$btn.text( i18n.copy || 'Copy' );
|
||||
}, 1500 );
|
||||
};
|
||||
if ( navigator.clipboard && navigator.clipboard.writeText ) {
|
||||
navigator.clipboard.writeText( text ).then( done );
|
||||
} else {
|
||||
var $tmp = $( '<textarea>' ).val( text ).appendTo( 'body' ).select();
|
||||
try {
|
||||
document.execCommand( 'copy' );
|
||||
} catch ( e ) {}
|
||||
$tmp.remove();
|
||||
done();
|
||||
}
|
||||
} );
|
||||
|
||||
/* ---------------- Test tenant ---------------- */
|
||||
$( '#m365-test' ).on( 'click', function () {
|
||||
var $btn = $( this );
|
||||
var $out = $( '#m365-test-result' );
|
||||
var label = $btn.text();
|
||||
|
||||
$btn.prop( 'disabled', true ).text( i18n.testing || '…' );
|
||||
$out.removeClass( 'is-success is-error' ).prop( 'hidden', true ).empty();
|
||||
|
||||
$.post( cfg.ajaxUrl, {
|
||||
action: cfg.action,
|
||||
nonce: cfg.nonce,
|
||||
tenant: $( '#m365-tenant' ).val()
|
||||
} ).done( function ( res ) {
|
||||
if ( res && res.success ) {
|
||||
$out.addClass( 'is-success' ).text( res.data.message ).append( $( '<code>' ).text( res.data.issuer ) );
|
||||
} else {
|
||||
$out.addClass( 'is-error' ).text( ( res && res.data && res.data.message ) || i18n.testFailed || '' );
|
||||
}
|
||||
} ).fail( function () {
|
||||
$out.addClass( 'is-error' ).text( i18n.testFailed || '' );
|
||||
} ).always( function () {
|
||||
$btn.prop( 'disabled', false ).text( label );
|
||||
$out.prop( 'hidden', false );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}( jQuery ) );
|
||||
20
assets/js/login.js
Normal file
20
assets/js/login.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* M365 Login – moves the button block directly below the login form. */
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
function place() {
|
||||
var block = document.getElementById( 'm365-login-block' );
|
||||
var form = document.getElementById( 'loginform' );
|
||||
if ( ! block || ! form || ! form.parentNode ) {
|
||||
return;
|
||||
}
|
||||
form.parentNode.insertBefore( block, form.nextSibling );
|
||||
document.body.classList.add( 'm365-login-attached' );
|
||||
}
|
||||
|
||||
if ( 'loading' === document.readyState ) {
|
||||
document.addEventListener( 'DOMContentLoaded', place );
|
||||
} else {
|
||||
place();
|
||||
}
|
||||
}() );
|
||||
27
bin/build-zip.sh
Executable file
27
bin/build-zip.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
# Builds build/m365-login.zip – the folder inside the archive is named after the
|
||||
# WordPress.org slug (m365-login), regardless of the repository name.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
SLUG="m365-login"
|
||||
BUILD="$ROOT/build"
|
||||
STAGE="$BUILD/$SLUG"
|
||||
|
||||
rm -rf "$BUILD"
|
||||
mkdir -p "$STAGE"
|
||||
|
||||
# rsync honours .distignore-style excludes.
|
||||
rsync -a --delete \
|
||||
--exclude-from="$ROOT/.distignore" \
|
||||
--exclude 'build' \
|
||||
"$ROOT/" "$STAGE/"
|
||||
|
||||
(
|
||||
cd "$BUILD"
|
||||
rm -f "$SLUG.zip"
|
||||
zip -rq "$SLUG.zip" "$SLUG"
|
||||
)
|
||||
|
||||
echo "Created $BUILD/$SLUG.zip"
|
||||
unzip -l "$BUILD/$SLUG.zip" | tail -n +4 | head -n -2 | awk '{print $4}'
|
||||
103
bin/compile-mo.py
Normal file
103
bin/compile-mo.py
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Compiles every languages/*.po into a binary .mo (no gettext tools required).
|
||||
|
||||
Usage: python3 bin/compile-mo.py
|
||||
"""
|
||||
import ast
|
||||
import glob
|
||||
import os
|
||||
import struct
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def parse_po(path):
|
||||
messages = {}
|
||||
ctx = msgid = msgstr = None
|
||||
plural = None
|
||||
plurals = {}
|
||||
section = None
|
||||
|
||||
def flush():
|
||||
if msgid is None:
|
||||
return
|
||||
key = msgid if ctx is None else ctx + "\x04" + msgid
|
||||
if plural is not None:
|
||||
key = key + "\x00" + plural
|
||||
value = "\x00".join(plurals[i] for i in sorted(plurals))
|
||||
else:
|
||||
value = msgstr or ""
|
||||
if msgid == "" or value:
|
||||
messages[key] = value
|
||||
|
||||
for raw in open(path, encoding="utf-8"):
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
if line.startswith("msgctxt "):
|
||||
flush()
|
||||
ctx, msgid, msgstr, plural, plurals = ast.literal_eval(line[8:]), None, None, None, {}
|
||||
section = "ctx"
|
||||
elif line.startswith("msgid_plural "):
|
||||
plural = ast.literal_eval(line[13:])
|
||||
section = "plural"
|
||||
elif line.startswith("msgid "):
|
||||
if section != "ctx":
|
||||
flush()
|
||||
ctx, msgstr, plural, plurals = None, None, None, {}
|
||||
msgid = ast.literal_eval(line[6:])
|
||||
section = "id"
|
||||
elif line.startswith("msgstr["):
|
||||
idx = int(line[7:line.index("]")])
|
||||
plurals[idx] = ast.literal_eval(line[line.index("]") + 1:].strip())
|
||||
section = ("pl", idx)
|
||||
elif line.startswith("msgstr "):
|
||||
msgstr = ast.literal_eval(line[7:])
|
||||
section = "str"
|
||||
elif line.startswith('"'):
|
||||
chunk = ast.literal_eval(line)
|
||||
if section == "ctx":
|
||||
ctx += chunk
|
||||
elif section == "id":
|
||||
msgid += chunk
|
||||
elif section == "plural":
|
||||
plural += chunk
|
||||
elif section == "str":
|
||||
msgstr += chunk
|
||||
elif isinstance(section, tuple):
|
||||
plurals[section[1]] += chunk
|
||||
flush()
|
||||
return messages
|
||||
|
||||
|
||||
def write_mo(messages, path):
|
||||
keys = sorted(messages)
|
||||
ids = b""
|
||||
strs = b""
|
||||
offsets = []
|
||||
for k in keys:
|
||||
kb = k.encode("utf-8")
|
||||
vb = messages[k].encode("utf-8")
|
||||
offsets.append((len(ids), len(kb), len(strs), len(vb)))
|
||||
ids += kb + b"\x00"
|
||||
strs += vb + b"\x00"
|
||||
n = len(keys)
|
||||
keystart = 7 * 4 + 16 * n
|
||||
valuestart = keystart + len(ids)
|
||||
koffsets = []
|
||||
voffsets = []
|
||||
for o1, l1, o2, l2 in offsets:
|
||||
koffsets += [l1, o1 + keystart]
|
||||
voffsets += [l2, o2 + valuestart]
|
||||
output = struct.pack("Iiiiiii", 0x950412DE, 0, n, 7 * 4, 7 * 4 + n * 8, 0, 0)
|
||||
output += struct.pack("%di" % len(koffsets), *koffsets)
|
||||
output += struct.pack("%di" % len(voffsets), *voffsets)
|
||||
output += ids + strs
|
||||
open(path, "wb").write(output)
|
||||
|
||||
|
||||
for po in sorted(glob.glob(os.path.join(ROOT, "languages", "*.po"))):
|
||||
mo = po[:-3] + ".mo"
|
||||
messages = parse_po(po)
|
||||
write_mo(messages, mo)
|
||||
print("Compiled %s (%d entries)" % (os.path.relpath(mo, ROOT), len(messages) - 1))
|
||||
94
bin/make-pot.py
Normal file
94
bin/make-pot.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Minimal POT generator for this plugin (fallback when WP-CLI is unavailable).
|
||||
|
||||
Usage: python3 bin/make-pot.py
|
||||
Prefer `wp i18n make-pot . languages/m365-login.pot` when WP-CLI is installed.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DOMAIN = "m365-login"
|
||||
FUNCS = r"(?:__|_e|esc_html__|esc_html_e|esc_attr__|esc_attr_e|_x|_ex|esc_html_x|esc_attr_x|_n|_nx)"
|
||||
STR = r"(?:'((?:[^'\\]|\\.)*)'|\"((?:[^\"\\]|\\.)*)\")"
|
||||
PATTERN = re.compile(FUNCS + r"\s*\(\s*" + STR + r"(?:\s*,\s*" + STR + r")?(?:\s*,\s*" + STR + r")?\s*[,)]", re.S)
|
||||
COMMENT = re.compile(r"/\*\s*translators:\s*(.*?)\*/", re.S)
|
||||
|
||||
|
||||
def unescape(s):
|
||||
return s.replace("\\'", "'").replace('\\"', '"').replace("\\\\", "\\")
|
||||
|
||||
|
||||
def po_escape(s):
|
||||
return s.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
|
||||
|
||||
|
||||
entries = OrderedDict()
|
||||
for dirpath, dirnames, filenames in os.walk(ROOT):
|
||||
dirnames[:] = [d for d in dirnames if d not in (".git", "vendor", "node_modules", "build", "bin", "docs", ".github", ".wordpress-org")]
|
||||
for fn in sorted(filenames):
|
||||
if not fn.endswith(".php"):
|
||||
continue
|
||||
path = os.path.join(dirpath, fn)
|
||||
rel = os.path.relpath(path, ROOT)
|
||||
src = open(path, encoding="utf-8").read()
|
||||
for m in PATTERN.finditer(src):
|
||||
func = m.group(0).split("(")[0].strip()
|
||||
msgid = unescape(m.group(1) if m.group(1) is not None else m.group(2))
|
||||
second = m.group(3) if m.group(3) is not None else m.group(4)
|
||||
third = m.group(5) if m.group(5) is not None else m.group(6)
|
||||
context = None
|
||||
plural = None
|
||||
if func in ("_x", "_ex", "esc_html_x", "esc_attr_x"):
|
||||
context = unescape(second) if second is not None else None
|
||||
elif func in ("_n",):
|
||||
plural = unescape(second) if second is not None else None
|
||||
elif func == "_nx":
|
||||
plural = unescape(second) if second is not None else None
|
||||
context = unescape(third) if third is not None else None
|
||||
line = src.count("\n", 0, m.start()) + 1
|
||||
before = src[max(0, m.start() - 400):m.start()]
|
||||
cm = COMMENT.findall(before)
|
||||
comment = " ".join(cm[-1].split()) if cm else None
|
||||
key = (context, msgid, plural)
|
||||
e = entries.setdefault(key, {"refs": [], "comment": None})
|
||||
e["refs"].append("%s:%d" % (rel, line))
|
||||
if comment:
|
||||
e["comment"] = comment
|
||||
|
||||
header = '''# Copyright (C) 2026 friloo
|
||||
# This file is distributed under the GPL-2.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: M365 Login 1.0.0\\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/friloo/wp-m365-login/issues\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
"POT-Creation-Date: 2026-09-22T00:00:00+00:00\\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\\n"
|
||||
"X-Generator: bin/make-pot.py\\n"
|
||||
"X-Domain: m365-login\\n"
|
||||
|
||||
'''
|
||||
out = [header]
|
||||
for (context, msgid, plural), e in entries.items():
|
||||
if e["comment"]:
|
||||
out.append("#. translators: %s\n" % e["comment"])
|
||||
out.append("#: %s\n" % " ".join(e["refs"]))
|
||||
if context:
|
||||
out.append('msgctxt "%s"\n' % po_escape(context))
|
||||
out.append('msgid "%s"\n' % po_escape(msgid))
|
||||
if plural:
|
||||
out.append('msgid_plural "%s"\n' % po_escape(plural))
|
||||
out.append('msgstr[0] ""\nmsgstr[1] ""\n\n')
|
||||
else:
|
||||
out.append('msgstr ""\n\n')
|
||||
|
||||
dest = os.path.join(ROOT, "languages", DOMAIN + ".pot")
|
||||
open(dest, "w", encoding="utf-8").write("".join(out))
|
||||
print("Wrote %s (%d strings)" % (os.path.relpath(dest, ROOT), len(entries)))
|
||||
29
composer.json
Normal file
29
composer.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "friloo/m365-login",
|
||||
"description": "Sign in to WordPress with Microsoft 365 / Entra ID (OpenID Connect with PKCE). Existing users are matched by e-mail address.",
|
||||
"type": "wordpress-plugin",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"homepage": "https://github.com/friloo/wp-m365-login",
|
||||
"require": {
|
||||
"php": ">=7.4",
|
||||
"ext-openssl": "*",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
||||
"wp-coding-standards/wpcs": "^3.1",
|
||||
"phpcompatibility/phpcompatibility-wp": "^2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l",
|
||||
"phpcs": "phpcs",
|
||||
"phpcbf": "phpcbf",
|
||||
"zip": "bash bin/build-zip.sh"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
},
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
||||
43
docs/wordpress-org-einreichung.md
Normal file
43
docs/wordpress-org-einreichung.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Checkliste: Einreichung im WordPress-Plugin-Verzeichnis
|
||||
|
||||
Das Plugin ist so aufgebaut, dass es die [Richtlinien des Plugin-Verzeichnisses](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/)
|
||||
erfüllt. Vor der Einreichung unter <https://wordpress.org/plugins/developers/add/> bitte die folgenden Punkte durchgehen.
|
||||
|
||||
## 1. Vor dem Upload prüfen
|
||||
|
||||
- [ ] `Tested up to:` in `readme.txt` auf die **aktuelle WordPress-Version** setzen (das Review-Team lehnt veraltete Werte ab).
|
||||
- [ ] `Stable tag:` in `readme.txt` und `Version:` in `m365-login.php` sowie `M365_LOGIN_VERSION` sind identisch.
|
||||
- [ ] `Contributors:` in `readme.txt` enthält deinen **WordPress.org-Benutzernamen** (aktuell `friloo`).
|
||||
- [ ] Übersetzungsdateien aktualisiert: `wp i18n make-pot . languages/m365-login.pot` (WP-CLI) oder `python3 bin/make-pot.py`, danach `python3 bin/compile-mo.py`.
|
||||
- [ ] `bash bin/build-zip.sh` ausführen und `build/m365-login.zip` hochladen (Ordner im ZIP heißt `m365-login`, nicht `wp-m365-login`).
|
||||
- [ ] Lokal den **Plugin Check** laufen lassen (Plugin „Plugin Check (PCP)“ installieren oder auf das CI-Ergebnis achten) – er muss ohne Fehler durchlaufen.
|
||||
|
||||
## 2. Namens- und Marken-Regeln
|
||||
|
||||
- Slugs dürfen nicht mit `wp-` oder mit Markennamen wie `microsoft-` beginnen; deshalb heißt der Slug `m365-login` und der Plugin-Name „M365 Login“.
|
||||
Sollte das Review-Team dennoch einen anderen Slug zuweisen (z. B. wegen Trademark-Bedenken bei „M365“), müssen **Text Domain**, Ordnername und `readme.txt` angepasst werden – Suche nach `m365-login` im Repo.
|
||||
- Der Name darf nicht suggerieren, dass das Plugin von Microsoft stammt. Beschreibungstexte verwenden deshalb Formulierungen wie „sign in with Microsoft“, nicht „official Microsoft plugin“.
|
||||
- Das Microsoft-Logo ist eingebettet, damit der Button so aussieht, wie Nutzer es erwarten. Microsoft erlaubt die Verwendung des Logos für „Sign in with Microsoft“-Buttons gemäß den [Branding-Richtlinien](https://learn.microsoft.com/entra/identity-platform/howto-add-branding-in-apps). Ein Reviewer könnte trotzdem nachfragen – der Hinweis auf diese Richtlinie reicht in der Regel.
|
||||
|
||||
## 3. Was bereits erfüllt ist
|
||||
|
||||
| Anforderung | Umsetzung |
|
||||
| --- | --- |
|
||||
| GPL-kompatible Lizenz | `LICENSE` (GPL-2.0), Header in `m365-login.php`, `readme.txt` |
|
||||
| `readme.txt` im WP-Format | inkl. Pflichtabschnitt **External services** (Microsoft-Endpunkte, übertragene Daten, Links zu Nutzungsbedingungen/Datenschutz) |
|
||||
| Keine externen Assets/CDNs | CSS/JS liegen im Plugin; einzige Netzwerkverbindungen gehen zu `login.microsoftonline.com` |
|
||||
| Sanitizing / Escaping / Nonces | Settings API mit `sanitize_callback`, `esc_*` bei jeder Ausgabe, `check_ajax_referer` + `current_user_can` |
|
||||
| Eindeutiges Präfix | `m365_login_` / `M365_Login_` für alle globalen Bezeichner |
|
||||
| Kein Tracking, keine Telefon-nach-Hause-Funktion | – |
|
||||
| Saubere Deinstallation | `uninstall.php` entfernt Option, Transients und User-Meta (auch Multisite) |
|
||||
| Keine minifizierten Dateien ohne Quelle | Alle Assets liegen unminifiziert vor |
|
||||
| `Requires PHP` / `Requires at least` | 7.4 / 6.0 |
|
||||
| Übersetzbar | Text Domain `m365-login`, `languages/m365-login.pot`, deutsche Übersetzung |
|
||||
|
||||
## 4. Nach der Freigabe
|
||||
|
||||
1. SVN-Zugang aus der Freigabe-Mail nutzen: `svn co https://plugins.svn.wordpress.org/m365-login`.
|
||||
2. Inhalt von `build/m365-login/` nach `trunk/` kopieren, `assets/` aus `.wordpress-org/` befüllen (Icon, Banner, Screenshots).
|
||||
3. `svn cp trunk tags/1.0.0` und committen.
|
||||
4. Screenshots erstellen (siehe `== Screenshots ==` in `readme.txt`) und als `screenshot-1.png` … in `assets/` ablegen.
|
||||
5. Optional: GitHub Action `10up/action-wordpress-plugin-deploy` einrichten, um Releases automatisch nach SVN zu spiegeln.
|
||||
460
includes/class-m365-login-admin.php
Normal file
460
includes/class-m365-login-admin.php
Normal file
|
|
@ -0,0 +1,460 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin settings screen.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Registers and renders the settings page.
|
||||
*/
|
||||
class M365_Login_Admin {
|
||||
|
||||
const PAGE = 'm365-login';
|
||||
const GROUP = 'm365_login';
|
||||
const AJAX_TEST = 'm365_login_test_connection';
|
||||
const NONCE_TEST = 'm365_login_test';
|
||||
|
||||
/**
|
||||
* Settings.
|
||||
*
|
||||
* @var M365_Login_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Auth component (for endpoint URLs and discovery).
|
||||
*
|
||||
* @var M365_Login_Auth
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* Screen hook suffix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $hook = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param M365_Login_Settings $settings Settings.
|
||||
* @param M365_Login_Auth $auth Auth.
|
||||
*/
|
||||
public function __construct( M365_Login_Settings $settings, M365_Login_Auth $auth ) {
|
||||
$this->settings = $settings;
|
||||
$this->auth = $auth;
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'menu' ) );
|
||||
add_action( 'admin_init', array( $this, 'register' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
||||
add_action( 'wp_ajax_' . self::AJAX_TEST, array( $this, 'ajax_test_connection' ) );
|
||||
add_action( 'admin_notices', array( $this, 'setup_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the menu entry under Settings.
|
||||
*/
|
||||
public function menu() {
|
||||
$this->hook = add_options_page(
|
||||
__( 'M365 Login', 'm365-login' ),
|
||||
__( 'M365 Login', 'm365-login' ),
|
||||
'manage_options',
|
||||
self::PAGE,
|
||||
array( $this, 'render' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the option with the Settings API.
|
||||
*/
|
||||
public function register() {
|
||||
register_setting(
|
||||
self::GROUP,
|
||||
M365_LOGIN_OPTION,
|
||||
array(
|
||||
'type' => 'array',
|
||||
'sanitize_callback' => array( $this->settings, 'sanitize' ),
|
||||
'default' => $this->settings->defaults(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nudges administrators to finish the setup.
|
||||
*/
|
||||
public function setup_notice() {
|
||||
if ( $this->settings->is_configured() || ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
$screen = get_current_screen();
|
||||
if ( $screen && $this->hook === $screen->id ) {
|
||||
return;
|
||||
}
|
||||
if ( ! $screen || ! in_array( $screen->id, array( 'plugins', 'dashboard' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
printf(
|
||||
'<div class="notice notice-info is-dismissible"><p>%s <a href="%s">%s</a></p></div>',
|
||||
esc_html__( 'M365 Login is active but not connected to Microsoft Entra ID yet.', 'm365-login' ),
|
||||
esc_url( admin_url( 'options-general.php?page=' . self::PAGE ) ),
|
||||
esc_html__( 'Open the settings', 'm365-login' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads assets on our screen only.
|
||||
*
|
||||
* @param string $hook Current screen hook.
|
||||
*/
|
||||
public function enqueue( $hook ) {
|
||||
if ( $hook !== $this->hook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_style( 'm365-login-admin', M365_LOGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), M365_LOGIN_VERSION );
|
||||
wp_enqueue_script( 'm365-login-admin', M365_LOGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker' ), M365_LOGIN_VERSION, true );
|
||||
|
||||
wp_localize_script(
|
||||
'm365-login-admin',
|
||||
'm365LoginAdmin',
|
||||
array(
|
||||
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( self::NONCE_TEST ),
|
||||
'action' => self::AJAX_TEST,
|
||||
'defaultLogo' => M365_Login_Button::microsoft_logo(),
|
||||
'i18n' => array(
|
||||
'chooseIcon' => __( 'Choose button icon', 'm365-login' ),
|
||||
'useIcon' => __( 'Use this icon', 'm365-login' ),
|
||||
'copied' => __( 'Copied!', 'm365-login' ),
|
||||
'copy' => __( 'Copy', 'm365-login' ),
|
||||
'testing' => __( 'Testing…', 'm365-login' ),
|
||||
'testFailed' => __( 'The tenant could not be reached. Check the tenant ID and the server’s outgoing connections.', 'm365-login' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: fetch the OpenID configuration for the tenant typed into the form.
|
||||
*/
|
||||
public function ajax_test_connection() {
|
||||
check_ajax_referer( self::NONCE_TEST, 'nonce' );
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( array( 'message' => __( 'You are not allowed to do this.', 'm365-login' ) ), 403 );
|
||||
}
|
||||
|
||||
$tenant = isset( $_POST['tenant'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['tenant'] ) ) ) : '';
|
||||
if ( '' === $tenant || ! M365_Login_Settings::is_valid_tenant( $tenant ) ) {
|
||||
wp_send_json_error( array( 'message' => __( 'Please enter a valid tenant ID first.', 'm365-login' ) ) );
|
||||
}
|
||||
|
||||
$url = 'https://login.microsoftonline.com/' . rawurlencode( $tenant ) . '/v2.0/.well-known/openid-configuration';
|
||||
$response = wp_remote_get( $url, array( 'timeout' => M365_Login_Auth::HTTP_TIMEOUT ) );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
wp_send_json_error( array( 'message' => $response->get_error_message() ) );
|
||||
}
|
||||
$code = (int) wp_remote_retrieve_response_code( $response );
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( 200 !== $code || ! is_array( $body ) || empty( $body['issuer'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
/* translators: %d: HTTP status code */
|
||||
'message' => sprintf( __( 'Microsoft answered with HTTP %d. Is the tenant ID correct?', 'm365-login' ), $code ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'issuer' => esc_url_raw( $body['issuer'] ),
|
||||
'endpoint' => isset( $body['authorization_endpoint'] ) ? esc_url_raw( $body['authorization_endpoint'] ) : '',
|
||||
'message' => __( 'Tenant reachable. The OpenID configuration was loaded successfully.', 'm365-login' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the settings screen.
|
||||
*/
|
||||
public function render() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You are not allowed to access this page.', 'm365-login' ) );
|
||||
}
|
||||
|
||||
$s = $this->settings->all();
|
||||
$configured = $this->settings->is_configured();
|
||||
$has_secret = '' !== $this->settings->client_secret();
|
||||
$option = M365_LOGIN_OPTION;
|
||||
$field = function ( $key ) use ( $option ) {
|
||||
return esc_attr( $option . '[' . $key . ']' );
|
||||
};
|
||||
?>
|
||||
<div class="wrap m365-admin">
|
||||
<header class="m365-admin__header">
|
||||
<div class="m365-admin__brand">
|
||||
<span class="m365-admin__logo"><?php echo M365_Login_Button::microsoft_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static SVG. ?></span>
|
||||
<div>
|
||||
<h1><?php esc_html_e( 'M365 Login', 'm365-login' ); ?></h1>
|
||||
<p><?php esc_html_e( 'Let existing users sign in with their Microsoft 365 / Entra ID account.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<span class="m365-admin__status <?php echo $configured ? 'is-ok' : 'is-pending'; ?>">
|
||||
<span class="m365-admin__status-dot"></span>
|
||||
<?php echo $configured ? esc_html__( 'Connected', 'm365-login' ) : esc_html__( 'Setup incomplete', 'm365-login' ); ?>
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<form method="post" action="options.php" class="m365-admin__form" novalidate>
|
||||
<?php settings_fields( self::GROUP ); ?>
|
||||
|
||||
<nav class="m365-admin__tabs" role="tablist">
|
||||
<button type="button" class="m365-admin__tab is-active" role="tab" data-tab="connection" aria-selected="true"><?php esc_html_e( 'Connection', 'm365-login' ); ?></button>
|
||||
<button type="button" class="m365-admin__tab" role="tab" data-tab="button" aria-selected="false"><?php esc_html_e( 'Button', 'm365-login' ); ?></button>
|
||||
<button type="button" class="m365-admin__tab" role="tab" data-tab="security" aria-selected="false"><?php esc_html_e( 'Security', 'm365-login' ); ?></button>
|
||||
</nav>
|
||||
|
||||
<div class="m365-admin__layout">
|
||||
<div class="m365-admin__main">
|
||||
|
||||
<!-- Connection -->
|
||||
<section class="m365-admin__panel is-active" data-panel="connection">
|
||||
<div class="m365-card">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'Microsoft Entra ID app registration', 'm365-login' ); ?></h2>
|
||||
<p class="m365-card__intro"><?php esc_html_e( 'Enter the values from your app registration in the Microsoft Entra admin center.', 'm365-login' ); ?></p>
|
||||
|
||||
<div class="m365-field">
|
||||
<label for="m365-tenant"><?php esc_html_e( 'Directory (tenant) ID', 'm365-login' ); ?></label>
|
||||
<div class="m365-field__row">
|
||||
<input type="text" id="m365-tenant" name="<?php echo $field( 'tenant_id' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s['tenant_id'] ); ?>" class="regular-text code" placeholder="00000000-0000-0000-0000-000000000000" autocomplete="off" spellcheck="false" />
|
||||
<button type="button" class="button" id="m365-test"><?php esc_html_e( 'Test tenant', 'm365-login' ); ?></button>
|
||||
</div>
|
||||
<p class="description"><?php esc_html_e( 'Recommended: the GUID of your tenant. Only sign-ins from this tenant are accepted. "organizations" allows any work or school account.', 'm365-login' ); ?></p>
|
||||
<div id="m365-test-result" class="m365-inline-result" hidden></div>
|
||||
</div>
|
||||
|
||||
<div class="m365-field">
|
||||
<label for="m365-client-id"><?php esc_html_e( 'Application (client) ID', 'm365-login' ); ?></label>
|
||||
<input type="text" id="m365-client-id" name="<?php echo $field( 'client_id' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s['client_id'] ); ?>" class="regular-text code" placeholder="00000000-0000-0000-0000-000000000000" autocomplete="off" spellcheck="false" />
|
||||
</div>
|
||||
|
||||
<div class="m365-field">
|
||||
<label for="m365-client-secret"><?php esc_html_e( 'Client secret', 'm365-login' ); ?></label>
|
||||
<div class="m365-field__row">
|
||||
<input type="password" id="m365-client-secret" name="<?php echo $field( 'client_secret' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="" class="regular-text code" autocomplete="new-password" placeholder="<?php echo $has_secret ? esc_attr__( '•••••••••••• (stored, leave empty to keep)', 'm365-login' ) : esc_attr__( 'Paste the secret value', 'm365-login' ); ?>" />
|
||||
<button type="button" class="button m365-toggle-secret" aria-label="<?php esc_attr_e( 'Show secret', 'm365-login' ); ?>"><span class="dashicons dashicons-visibility"></span></button>
|
||||
</div>
|
||||
<?php if ( $has_secret ) : ?>
|
||||
<label class="m365-check m365-check--inline">
|
||||
<input type="checkbox" name="<?php echo $field( 'client_secret_clear' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="1" />
|
||||
<?php esc_html_e( 'Remove the stored secret', 'm365-login' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<p class="description"><?php esc_html_e( 'Stored encrypted (AES-256-GCM, key derived from your WordPress salts) and never displayed again. Client secrets expire – note the expiry date in Entra ID.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="m365-field">
|
||||
<label for="m365-prompt"><?php esc_html_e( 'Account prompt', 'm365-login' ); ?></label>
|
||||
<select id="m365-prompt" name="<?php echo $field( 'prompt' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>">
|
||||
<option value="select_account" <?php selected( $s['prompt'], 'select_account' ); ?>><?php esc_html_e( 'Always let the user pick an account (recommended)', 'm365-login' ); ?></option>
|
||||
<option value="none" <?php selected( $s['prompt'], 'none' ); ?>><?php esc_html_e( 'Use the current Microsoft session if available', 'm365-login' ); ?></option>
|
||||
<option value="login" <?php selected( $s['prompt'], 'login' ); ?>><?php esc_html_e( 'Always require re-entering credentials', 'm365-login' ); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Button -->
|
||||
<section class="m365-admin__panel" data-panel="button">
|
||||
<div class="m365-card">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'Appearance', 'm365-login' ); ?></h2>
|
||||
|
||||
<div class="m365-preview">
|
||||
<span class="m365-preview__label"><?php esc_html_e( 'Live preview', 'm365-login' ); ?></span>
|
||||
<div class="m365-preview__stage">
|
||||
<div class="m365-login m365-login--preview" id="m365-preview" style="<?php echo esc_attr( str_replace( array( '.m365-login{', '}' ), '', M365_Login::instance()->button->css_variables() ) ); ?>">
|
||||
<div class="m365-login__divider"><span id="m365-preview-divider"><?php echo esc_html( $s['divider_text'] ); ?></span></div>
|
||||
<a class="m365-login__button" href="#" onclick="return false;" id="m365-preview-button">
|
||||
<span id="m365-preview-icon"><?php echo M365_Login_Button::microsoft_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static SVG. ?></span>
|
||||
<span class="m365-login__label" id="m365-preview-text"><?php echo esc_html( $s['button_text'] ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m365-grid">
|
||||
<div class="m365-field">
|
||||
<label for="m365-button-text"><?php esc_html_e( 'Button text', 'm365-login' ); ?></label>
|
||||
<input type="text" id="m365-button-text" name="<?php echo $field( 'button_text' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s['button_text'] ); ?>" class="regular-text" maxlength="80" data-preview="text" />
|
||||
</div>
|
||||
<div class="m365-field">
|
||||
<label for="m365-divider-text"><?php esc_html_e( 'Divider text', 'm365-login' ); ?></label>
|
||||
<input type="text" id="m365-divider-text" name="<?php echo $field( 'divider_text' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s['divider_text'] ); ?>" class="regular-text" maxlength="40" data-preview="divider" />
|
||||
<p class="description"><?php esc_html_e( 'Leave empty to hide the divider line.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m365-field">
|
||||
<span class="m365-field__label"><?php esc_html_e( 'Icon', 'm365-login' ); ?></span>
|
||||
<label class="m365-check">
|
||||
<input type="checkbox" name="<?php echo $field( 'button_show_icon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="1" <?php checked( $s['button_show_icon'] ); ?> data-preview="show-icon" />
|
||||
<?php esc_html_e( 'Show an icon on the button', 'm365-login' ); ?>
|
||||
</label>
|
||||
<div class="m365-icon-picker">
|
||||
<div class="m365-icon-picker__thumb" id="m365-icon-thumb">
|
||||
<?php if ( '' !== $s['button_icon'] ) : ?>
|
||||
<img src="<?php echo esc_url( $s['button_icon'] ); ?>" alt="" />
|
||||
<?php else : ?>
|
||||
<?php echo M365_Login_Button::microsoft_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static SVG. ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="m365-icon-picker__controls">
|
||||
<input type="url" id="m365-icon-url" name="<?php echo $field( 'button_icon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_url( $s['button_icon'] ); ?>" class="regular-text code" placeholder="<?php esc_attr_e( 'Default: Microsoft logo', 'm365-login' ); ?>" data-preview="icon" />
|
||||
<div class="m365-field__row">
|
||||
<button type="button" class="button" id="m365-icon-choose"><?php esc_html_e( 'Choose from media library', 'm365-login' ); ?></button>
|
||||
<button type="button" class="button-link m365-link-danger" id="m365-icon-reset"><?php esc_html_e( 'Use Microsoft logo', 'm365-login' ); ?></button>
|
||||
</div>
|
||||
<p class="description"><?php esc_html_e( 'PNG, SVG, JPG or WebP. Square images (e.g. 64×64 px) work best.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m365-grid m365-grid--4">
|
||||
<?php
|
||||
$colors = array(
|
||||
'button_bg' => __( 'Background', 'm365-login' ),
|
||||
'button_bg_hover' => __( 'Background (hover)', 'm365-login' ),
|
||||
'button_color' => __( 'Text colour', 'm365-login' ),
|
||||
'button_border' => __( 'Border', 'm365-login' ),
|
||||
);
|
||||
foreach ( $colors as $key => $label ) :
|
||||
?>
|
||||
<div class="m365-field">
|
||||
<label for="m365-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></label>
|
||||
<input type="text" id="m365-<?php echo esc_attr( $key ); ?>" name="<?php echo $field( $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s[ $key ] ); ?>" class="m365-color" data-default-color="<?php echo esc_attr( $this->settings->defaults()[ $key ] ); ?>" data-preview="<?php echo esc_attr( str_replace( 'button_', '', $key ) ); ?>" />
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="m365-grid">
|
||||
<div class="m365-field">
|
||||
<label for="m365-radius"><?php esc_html_e( 'Corner radius', 'm365-login' ); ?> <span class="m365-range-value" id="m365-radius-value"><?php echo esc_html( $s['button_radius'] ); ?> px</span></label>
|
||||
<input type="range" id="m365-radius" name="<?php echo $field( 'button_radius' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="<?php echo esc_attr( $s['button_radius'] ); ?>" min="0" max="50" step="1" data-preview="radius" />
|
||||
</div>
|
||||
<div class="m365-field">
|
||||
<label for="m365-position"><?php esc_html_e( 'Position on the login page', 'm365-login' ); ?></label>
|
||||
<select id="m365-position" name="<?php echo $field( 'button_position' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>">
|
||||
<option value="below" <?php selected( $s['button_position'], 'below' ); ?>><?php esc_html_e( 'Below the login form', 'm365-login' ); ?></option>
|
||||
<option value="above" <?php selected( $s['button_position'], 'above' ); ?>><?php esc_html_e( 'Above the login form', 'm365-login' ); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m365-presets">
|
||||
<span class="m365-field__label"><?php esc_html_e( 'Quick presets', 'm365-login' ); ?></span>
|
||||
<button type="button" class="m365-preset" data-preset='{"bg":"#2f2f2f","bg_hover":"#1a1a1a","color":"#ffffff","border":"#2f2f2f"}'><span style="background:#2f2f2f"></span><?php esc_html_e( 'Microsoft dark', 'm365-login' ); ?></button>
|
||||
<button type="button" class="m365-preset" data-preset='{"bg":"#ffffff","bg_hover":"#f3f3f3","color":"#5e5e5e","border":"#8c8c8c"}'><span style="background:#ffffff;border-color:#8c8c8c"></span><?php esc_html_e( 'Microsoft light', 'm365-login' ); ?></button>
|
||||
<button type="button" class="m365-preset" data-preset='{"bg":"#0078d4","bg_hover":"#106ebe","color":"#ffffff","border":"#0078d4"}'><span style="background:#0078d4"></span><?php esc_html_e( 'Azure blue', 'm365-login' ); ?></button>
|
||||
<button type="button" class="m365-preset" data-preset='{"bg":"#2271b1","bg_hover":"#135e96","color":"#ffffff","border":"#2271b1"}'><span style="background:#2271b1"></span><?php esc_html_e( 'WordPress blue', 'm365-login' ); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Security -->
|
||||
<section class="m365-admin__panel" data-panel="security">
|
||||
<div class="m365-card">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'User matching & hardening', 'm365-login' ); ?></h2>
|
||||
<p class="m365-card__intro"><?php esc_html_e( 'Users are never created automatically. A Microsoft sign-in only succeeds when a WordPress user with the same e-mail address already exists.', 'm365-login' ); ?></p>
|
||||
|
||||
<label class="m365-check m365-check--block">
|
||||
<input type="checkbox" name="<?php echo $field( 'bind_oid' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="1" <?php checked( $s['bind_oid'] ); ?> />
|
||||
<span>
|
||||
<strong><?php esc_html_e( 'Bind WordPress accounts to the Microsoft object ID', 'm365-login' ); ?></strong>
|
||||
<em><?php esc_html_e( 'On first sign-in the immutable Microsoft object ID is stored with the user. Later sign-ins with the same e-mail but a different Microsoft identity are rejected. Strongly recommended.', 'm365-login' ); ?></em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label class="m365-check m365-check--block">
|
||||
<input type="checkbox" name="<?php echo $field( 'upn_fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="1" <?php checked( $s['upn_fallback'] ); ?> />
|
||||
<span>
|
||||
<strong><?php esc_html_e( 'Fall back to the user principal name (UPN)', 'm365-login' ); ?></strong>
|
||||
<em><?php esc_html_e( 'If the token contains no "email" claim, use the UPN (e.g. jane@contoso.com) when it is a valid e-mail address. Usually required for work accounts.', 'm365-login' ); ?></em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label class="m365-check m365-check--block">
|
||||
<input type="checkbox" name="<?php echo $field( 'remember_me' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" value="1" <?php checked( $s['remember_me'] ); ?> />
|
||||
<span>
|
||||
<strong><?php esc_html_e( 'Keep users signed in ("Remember me")', 'm365-login' ); ?></strong>
|
||||
<em><?php esc_html_e( 'Issues a 14-day WordPress session instead of a browser session.', 'm365-login' ); ?></em>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="m365-field">
|
||||
<label for="m365-domains"><?php esc_html_e( 'Allowed e-mail domains (optional)', 'm365-login' ); ?></label>
|
||||
<textarea id="m365-domains" name="<?php echo $field( 'allowed_domains' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" rows="3" class="large-text code" placeholder="contoso.com, contoso.de"><?php echo esc_textarea( $s['allowed_domains'] ); ?></textarea>
|
||||
<p class="description"><?php esc_html_e( 'One or more domains separated by commas or new lines. Leave empty to allow any domain of your tenant.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m365-card m365-card--muted">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'What the plugin does to keep sign-ins safe', 'm365-login' ); ?></h2>
|
||||
<ul class="m365-list">
|
||||
<li><?php esc_html_e( 'OpenID Connect authorization code flow with PKCE (S256) – no tokens ever pass through the browser.', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Single-use state and nonce values bound to the browser via an HttpOnly cookie (CSRF and replay protection).', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'ID token signature verified against Microsoft’s published signing keys; issuer, audience, tenant, expiry and nonce are checked.', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Client secret encrypted at rest; no accounts are created, no passwords are changed.', 'm365-login' ); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="m365-admin__actions">
|
||||
<?php submit_button( __( 'Save changes', 'm365-login' ), 'primary large', 'submit', false ); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="m365-admin__sidebar">
|
||||
<div class="m365-card m365-card--accent">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'Redirect URI', 'm365-login' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Register this URI in your app registration under Authentication → Web → Redirect URIs:', 'm365-login' ); ?></p>
|
||||
<div class="m365-copy">
|
||||
<code id="m365-redirect-uri"><?php echo esc_html( $this->settings->redirect_uri() ); ?></code>
|
||||
<button type="button" class="button button-small m365-copy__button" data-copy="m365-redirect-uri"><?php esc_html_e( 'Copy', 'm365-login' ); ?></button>
|
||||
</div>
|
||||
<?php if ( ! $this->settings->uses_pretty_callback() ) : ?>
|
||||
<p class="description"><?php esc_html_e( 'Plain permalinks are active, so the callback uses a query string. If you enable pretty permalinks later, the redirect URI changes and must be updated in Entra ID.', 'm365-login' ); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! is_ssl() && 'https' !== wp_parse_url( home_url(), PHP_URL_SCHEME ) ) : ?>
|
||||
<p class="m365-warning"><?php esc_html_e( 'Your site does not use HTTPS. Microsoft only accepts http:// redirect URIs for localhost; production sites must use HTTPS.', 'm365-login' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="m365-card">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'Setup in 5 steps', 'm365-login' ); ?></h2>
|
||||
<ol class="m365-steps">
|
||||
<li><?php esc_html_e( 'Open the Microsoft Entra admin center → App registrations → New registration.', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Choose "Accounts in this organizational directory only", set the platform to Web and paste the redirect URI above.', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Copy the Application (client) ID and Directory (tenant) ID from the overview page.', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Under Certificates & secrets create a client secret and copy its value (not the ID).', 'm365-login' ); ?></li>
|
||||
<li><?php esc_html_e( 'Under Token configuration add the optional claim "email" for ID tokens (recommended), then save this page.', 'm365-login' ); ?></li>
|
||||
</ol>
|
||||
<p class="description"><?php esc_html_e( 'Required API permission: openid, profile, email (delegated) – granted by default.', 'm365-login' ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="m365-card m365-card--muted">
|
||||
<h2 class="m365-card__title"><?php esc_html_e( 'Shortcode', 'm365-login' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Place the button on a custom login page:', 'm365-login' ); ?></p>
|
||||
<code>[m365_login_button redirect="/my-account/"]</code>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
617
includes/class-m365-login-auth.php
Normal file
617
includes/class-m365-login-auth.php
Normal file
|
|
@ -0,0 +1,617 @@
|
|||
<?php
|
||||
/**
|
||||
* OpenID Connect authorization code flow (with PKCE) against Microsoft Entra ID.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Handles the login start, the callback and user matching.
|
||||
*/
|
||||
class M365_Login_Auth {
|
||||
|
||||
const ACTION_START = 'm365_login';
|
||||
const CALLBACK_PATH = 'm365-login/callback';
|
||||
const STATE_COOKIE = 'm365_login_state';
|
||||
const STATE_TTL = 600; // 10 minutes.
|
||||
const META_OID = '_m365_login_oid';
|
||||
const META_LAST_LOGIN = '_m365_login_last_login';
|
||||
const JWKS_CACHE_TTL = 12 * HOUR_IN_SECONDS;
|
||||
const HTTP_TIMEOUT = 15;
|
||||
|
||||
/**
|
||||
* Settings.
|
||||
*
|
||||
* @var M365_Login_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param M365_Login_Settings $settings Settings.
|
||||
*/
|
||||
public function __construct( M365_Login_Settings $settings ) {
|
||||
$this->settings = $settings;
|
||||
|
||||
add_action( 'login_form_' . self::ACTION_START, array( $this, 'handle_start' ) );
|
||||
add_action( 'init', array( $this, 'maybe_handle_callback' ), 5 );
|
||||
add_filter( 'wp_login_errors', array( $this, 'login_errors' ), 10, 1 );
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Endpoints */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Microsoft authority base URL for the configured tenant.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function authority() {
|
||||
return 'https://login.microsoftonline.com/' . rawurlencode( $this->settings->tenant() );
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenID configuration document URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function discovery_url() {
|
||||
return $this->authority() . '/v2.0/.well-known/openid-configuration';
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization endpoint.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function authorize_endpoint() {
|
||||
return $this->authority() . '/oauth2/v2.0/authorize';
|
||||
}
|
||||
|
||||
/**
|
||||
* Token endpoint.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function token_endpoint() {
|
||||
return $this->authority() . '/oauth2/v2.0/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* JWKS endpoint.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jwks_endpoint() {
|
||||
return $this->authority() . '/discovery/v2.0/keys';
|
||||
}
|
||||
|
||||
/**
|
||||
* URL that starts the Microsoft login.
|
||||
*
|
||||
* @param string $redirect_to Optional destination after login.
|
||||
* @return string
|
||||
*/
|
||||
public function start_url( $redirect_to = '' ) {
|
||||
$args = array( 'action' => self::ACTION_START );
|
||||
if ( '' !== $redirect_to ) {
|
||||
$args['redirect_to'] = $redirect_to;
|
||||
}
|
||||
return add_query_arg( $args, wp_login_url() );
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Step 1: redirect to Microsoft */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Builds the authorization request and redirects the browser.
|
||||
*/
|
||||
public function handle_start() {
|
||||
if ( ! $this->settings->is_configured() ) {
|
||||
$this->fail( 'not_configured' );
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- redirect_to is validated with wp_validate_redirect() before use.
|
||||
$redirect_to = isset( $_GET['redirect_to'] ) ? wp_validate_redirect( esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ), '' ) : '';
|
||||
|
||||
$state = M365_Login_JWT::b64url_encode( random_bytes( 32 ) );
|
||||
$nonce = M365_Login_JWT::b64url_encode( random_bytes( 32 ) );
|
||||
$code_verifier = M365_Login_JWT::b64url_encode( random_bytes( 64 ) );
|
||||
$cookie_token = M365_Login_JWT::b64url_encode( random_bytes( 32 ) );
|
||||
|
||||
$code_challenge = M365_Login_JWT::b64url_encode( hash( 'sha256', $code_verifier, true ) );
|
||||
|
||||
// The transient is keyed by a hash of the state, so the raw state never hits the database.
|
||||
set_transient(
|
||||
$this->state_key( $state ),
|
||||
array(
|
||||
'nonce' => $nonce,
|
||||
'verifier' => $code_verifier,
|
||||
'cookie' => hash( 'sha256', $cookie_token ),
|
||||
'redirect_to' => $redirect_to,
|
||||
'created' => time(),
|
||||
),
|
||||
self::STATE_TTL
|
||||
);
|
||||
|
||||
$this->set_state_cookie( $cookie_token );
|
||||
|
||||
$params = array(
|
||||
'client_id' => $this->settings->get( 'client_id' ),
|
||||
'response_type' => 'code',
|
||||
'redirect_uri' => $this->settings->redirect_uri(),
|
||||
'response_mode' => 'query',
|
||||
'scope' => 'openid profile email',
|
||||
'state' => $state,
|
||||
'nonce' => $nonce,
|
||||
'code_challenge' => $code_challenge,
|
||||
'code_challenge_method' => 'S256',
|
||||
);
|
||||
|
||||
$prompt = $this->settings->get( 'prompt' );
|
||||
if ( in_array( $prompt, array( 'select_account', 'login' ), true ) ) {
|
||||
$params['prompt'] = $prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the parameters sent to the Microsoft authorization endpoint.
|
||||
*
|
||||
* @param array $params Query parameters.
|
||||
*/
|
||||
$params = apply_filters( 'm365_login_authorize_params', $params );
|
||||
|
||||
nocache_headers();
|
||||
wp_redirect( $this->authorize_endpoint() . '?' . http_build_query( $params, '', '&', PHP_QUERY_RFC3986 ) ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- external IdP redirect by design.
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Step 2: callback */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Detects a request to /m365-login/callback regardless of permalink settings.
|
||||
*/
|
||||
public function maybe_handle_callback() {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only; the OAuth state is verified in handle_callback().
|
||||
$query_form = isset( $_GET['m365-login'] ) && 'callback' === sanitize_key( wp_unslash( $_GET['m365-login'] ) );
|
||||
|
||||
$path_form = false;
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
|
||||
$request_path = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH );
|
||||
$expected = wp_parse_url( home_url( '/' . self::CALLBACK_PATH ), PHP_URL_PATH );
|
||||
$path_form = is_string( $request_path ) && is_string( $expected )
|
||||
&& untrailingslashit( $request_path ) === untrailingslashit( $expected );
|
||||
}
|
||||
|
||||
if ( ! $query_form && ! $path_form ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->handle_callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the authorization response, exchanges the code, verifies the
|
||||
* ID token and signs the matching WordPress user in.
|
||||
*/
|
||||
private function handle_callback() {
|
||||
nocache_headers();
|
||||
|
||||
if ( ! $this->settings->is_configured() ) {
|
||||
$this->fail( 'not_configured' );
|
||||
}
|
||||
|
||||
// State is the CSRF token for this request; there is no WP nonce by design.
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$state = isset( $_GET['state'] ) ? sanitize_text_field( wp_unslash( $_GET['state'] ) ) : '';
|
||||
$code = isset( $_GET['code'] ) ? sanitize_text_field( wp_unslash( $_GET['code'] ) ) : '';
|
||||
$error = isset( $_GET['error'] ) ? sanitize_key( wp_unslash( $_GET['error'] ) ) : '';
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( '' === $state || ! preg_match( '/^[A-Za-z0-9_\-]{20,128}$/', $state ) ) {
|
||||
$this->fail( 'invalid_state' );
|
||||
}
|
||||
|
||||
// Consume the state immediately: every state is single use.
|
||||
$key = $this->state_key( $state );
|
||||
$attempt = get_transient( $key );
|
||||
delete_transient( $key );
|
||||
|
||||
if ( ! is_array( $attempt ) || empty( $attempt['nonce'] ) || empty( $attempt['verifier'] ) || empty( $attempt['cookie'] ) ) {
|
||||
$this->fail( 'invalid_state' );
|
||||
}
|
||||
if ( empty( $attempt['created'] ) || ( time() - (int) $attempt['created'] ) > self::STATE_TTL ) {
|
||||
$this->fail( 'invalid_state' );
|
||||
}
|
||||
|
||||
// Bind the callback to the browser that started the flow.
|
||||
$cookie_token = isset( $_COOKIE[ self::STATE_COOKIE ] ) ? sanitize_text_field( wp_unslash( $_COOKIE[ self::STATE_COOKIE ] ) ) : '';
|
||||
$this->clear_state_cookie();
|
||||
if ( '' === $cookie_token || ! hash_equals( $attempt['cookie'], hash( 'sha256', $cookie_token ) ) ) {
|
||||
$this->fail( 'invalid_state' );
|
||||
}
|
||||
|
||||
if ( '' !== $error ) {
|
||||
$this->fail( 'access_denied' === $error ? 'access_denied' : 'provider_error' );
|
||||
}
|
||||
if ( '' === $code ) {
|
||||
$this->fail( 'provider_error' );
|
||||
}
|
||||
|
||||
$tokens = $this->exchange_code( $code, $attempt['verifier'] );
|
||||
if ( is_wp_error( $tokens ) ) {
|
||||
$this->log( 'Token exchange failed: ' . $tokens->get_error_message() );
|
||||
$this->fail( 'token_exchange' );
|
||||
}
|
||||
|
||||
$claims = $this->verify_id_token( $tokens['id_token'], $attempt['nonce'] );
|
||||
if ( is_wp_error( $claims ) ) {
|
||||
$this->log( 'ID token rejected: ' . $claims->get_error_message() );
|
||||
$this->fail( 'invalid_token' );
|
||||
}
|
||||
|
||||
$email = $this->email_from_claims( $claims );
|
||||
if ( '' === $email ) {
|
||||
$this->fail( 'no_email' );
|
||||
}
|
||||
|
||||
if ( ! $this->domain_allowed( $email ) ) {
|
||||
$this->fail( 'domain_not_allowed' );
|
||||
}
|
||||
|
||||
$user = get_user_by( 'email', $email );
|
||||
if ( ! $user instanceof WP_User ) {
|
||||
/** This action is documented in wp-includes/user.php */
|
||||
do_action( 'wp_login_failed', $email, new WP_Error( 'm365_login_no_user', 'No WordPress user with this e-mail address.' ) );
|
||||
$this->fail( 'no_user' );
|
||||
}
|
||||
|
||||
if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) && ! is_super_admin( $user->ID ) ) {
|
||||
$this->fail( 'no_user' );
|
||||
}
|
||||
|
||||
// Bind the account to the immutable Microsoft object ID after first login.
|
||||
$oid = isset( $claims['oid'] ) && is_string( $claims['oid'] ) ? strtolower( $claims['oid'] ) : '';
|
||||
if ( $this->settings->get( 'bind_oid' ) ) {
|
||||
if ( '' === $oid || ! M365_Login_Settings::is_guid( $oid ) ) {
|
||||
$this->fail( 'invalid_token' );
|
||||
}
|
||||
$stored = (string) get_user_meta( $user->ID, self::META_OID, true );
|
||||
if ( '' !== $stored && ! hash_equals( $stored, $oid ) ) {
|
||||
$this->log( sprintf( 'Object ID mismatch for user #%d.', $user->ID ) );
|
||||
$this->fail( 'oid_mismatch' );
|
||||
}
|
||||
if ( '' === $stored ) {
|
||||
update_user_meta( $user->ID, self::META_OID, $oid );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows blocking a login after all checks passed (e.g. group membership).
|
||||
*
|
||||
* @param bool|WP_Error $allowed True to allow.
|
||||
* @param WP_User $user Matched user.
|
||||
* @param array $claims Verified ID token claims.
|
||||
*/
|
||||
$allowed = apply_filters( 'm365_login_allow_user', true, $user, $claims );
|
||||
if ( true !== $allowed ) {
|
||||
$this->fail( 'not_allowed' );
|
||||
}
|
||||
|
||||
update_user_meta( $user->ID, self::META_LAST_LOGIN, time() );
|
||||
|
||||
$remember = (bool) $this->settings->get( 'remember_me' );
|
||||
wp_set_current_user( $user->ID );
|
||||
wp_set_auth_cookie( $user->ID, $remember, is_ssl() );
|
||||
|
||||
/** This action is documented in wp-includes/user.php */
|
||||
do_action( 'wp_login', $user->user_login, $user );
|
||||
|
||||
/**
|
||||
* Fires after a successful Microsoft login.
|
||||
*
|
||||
* @param WP_User $user User.
|
||||
* @param array $claims Verified claims.
|
||||
*/
|
||||
do_action( 'm365_login_success', $user, $claims );
|
||||
|
||||
$redirect_to = ! empty( $attempt['redirect_to'] ) ? $attempt['redirect_to'] : admin_url();
|
||||
/** This filter is documented in wp-login.php */
|
||||
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $redirect_to, $user );
|
||||
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Helpers */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Exchanges the authorization code for tokens.
|
||||
*
|
||||
* @param string $code Authorization code.
|
||||
* @param string $verifier PKCE verifier.
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
private function exchange_code( $code, $verifier ) {
|
||||
$response = wp_remote_post(
|
||||
$this->token_endpoint(),
|
||||
array(
|
||||
'timeout' => self::HTTP_TIMEOUT,
|
||||
'headers' => array( 'Accept' => 'application/json' ),
|
||||
'body' => array(
|
||||
'client_id' => $this->settings->get( 'client_id' ),
|
||||
'client_secret' => $this->settings->client_secret(),
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->settings->redirect_uri(),
|
||||
'code_verifier' => $verifier,
|
||||
'scope' => 'openid profile email',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
$http = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 !== $http || ! is_array( $body ) ) {
|
||||
$detail = is_array( $body ) && ! empty( $body['error'] ) ? (string) $body['error'] : 'HTTP ' . $http;
|
||||
return new WP_Error( 'token_http', $detail );
|
||||
}
|
||||
if ( empty( $body['id_token'] ) || ! is_string( $body['id_token'] ) ) {
|
||||
return new WP_Error( 'token_missing', 'No id_token in response.' );
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the ID token, refreshing the JWKS cache once on an unknown key ID.
|
||||
*
|
||||
* @param string $id_token Token.
|
||||
* @param string $nonce Expected nonce.
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
private function verify_id_token( $id_token, $nonce ) {
|
||||
$tenant = $this->settings->tenant();
|
||||
$expected = array(
|
||||
'aud' => (string) $this->settings->get( 'client_id' ),
|
||||
'nonce' => $nonce,
|
||||
'tenant' => M365_Login_Settings::is_guid( $tenant ) ? $tenant : '',
|
||||
);
|
||||
|
||||
$jwks = $this->get_jwks( false );
|
||||
if ( is_wp_error( $jwks ) ) {
|
||||
return $jwks;
|
||||
}
|
||||
|
||||
$claims = M365_Login_JWT::verify( $id_token, $jwks, $expected );
|
||||
if ( is_wp_error( $claims ) && 'jwt_unknown_kid' === $claims->get_error_code() ) {
|
||||
// Key rollover: fetch a fresh key set and try once more.
|
||||
$jwks = $this->get_jwks( true );
|
||||
if ( is_wp_error( $jwks ) ) {
|
||||
return $jwks;
|
||||
}
|
||||
$claims = M365_Login_JWT::verify( $id_token, $jwks, $expected );
|
||||
}
|
||||
|
||||
return $claims;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches (and caches) the JWKS document.
|
||||
*
|
||||
* @param bool $force Bypass cache.
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
private function get_jwks( $force = false ) {
|
||||
$cache_key = 'm365_login_jwks_' . md5( $this->jwks_endpoint() );
|
||||
|
||||
if ( ! $force ) {
|
||||
$cached = get_transient( $cache_key );
|
||||
if ( is_array( $cached ) && ! empty( $cached['keys'] ) ) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
|
||||
$response = wp_remote_get( $this->jwks_endpoint(), array( 'timeout' => self::HTTP_TIMEOUT ) );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
|
||||
return new WP_Error( 'jwks_http', 'JWKS endpoint returned HTTP ' . wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
$jwks = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( ! is_array( $jwks ) || empty( $jwks['keys'] ) || ! is_array( $jwks['keys'] ) ) {
|
||||
return new WP_Error( 'jwks_format', 'JWKS document is invalid.' );
|
||||
}
|
||||
|
||||
set_transient( $cache_key, $jwks, self::JWKS_CACHE_TTL );
|
||||
return $jwks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the OpenID configuration (used by the admin "test connection" button).
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function fetch_discovery() {
|
||||
$response = wp_remote_get( $this->discovery_url(), array( 'timeout' => self::HTTP_TIMEOUT ) );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
$code = (int) wp_remote_retrieve_response_code( $response );
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( 200 !== $code || ! is_array( $body ) || empty( $body['issuer'] ) ) {
|
||||
return new WP_Error( 'discovery', sprintf( 'HTTP %d', $code ) );
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the e-mail address used for matching.
|
||||
*
|
||||
* @param array $claims Verified claims.
|
||||
* @return string Lowercase e-mail or empty string.
|
||||
*/
|
||||
private function email_from_claims( $claims ) {
|
||||
$candidates = array();
|
||||
if ( ! empty( $claims['email'] ) && is_string( $claims['email'] ) ) {
|
||||
$candidates[] = $claims['email'];
|
||||
}
|
||||
if ( $this->settings->get( 'upn_fallback' ) && ! empty( $claims['preferred_username'] ) && is_string( $claims['preferred_username'] ) ) {
|
||||
$candidates[] = $claims['preferred_username'];
|
||||
}
|
||||
|
||||
foreach ( $candidates as $candidate ) {
|
||||
$candidate = strtolower( trim( $candidate ) );
|
||||
if ( is_email( $candidate ) ) {
|
||||
/**
|
||||
* Filters the e-mail address used to look up the WordPress user.
|
||||
*
|
||||
* @param string $email E-mail from the token.
|
||||
* @param array $claims Verified claims.
|
||||
*/
|
||||
return (string) apply_filters( 'm365_login_match_email', $candidate, $claims );
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the optional domain allow-list.
|
||||
*
|
||||
* @param string $email E-mail.
|
||||
* @return bool
|
||||
*/
|
||||
private function domain_allowed( $email ) {
|
||||
$allowed = $this->settings->allowed_domains();
|
||||
if ( empty( $allowed ) ) {
|
||||
return true;
|
||||
}
|
||||
$domain = strtolower( substr( strrchr( $email, '@' ), 1 ) );
|
||||
return in_array( $domain, $allowed, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Transient key for a state value.
|
||||
*
|
||||
* @param string $state State.
|
||||
* @return string
|
||||
*/
|
||||
private function state_key( $state ) {
|
||||
return 'm365_login_st_' . hash_hmac( 'sha256', $state, wp_salt( 'nonce' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the short-lived state cookie.
|
||||
*
|
||||
* @param string $token Cookie value.
|
||||
*/
|
||||
private function set_state_cookie( $token ) {
|
||||
$this->send_cookie( $token, time() + self::STATE_TTL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the state cookie.
|
||||
*/
|
||||
private function clear_state_cookie() {
|
||||
$this->send_cookie( '', time() - YEAR_IN_SECONDS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cookie helper: HttpOnly, SameSite=Lax (needed for the top-level redirect back), Secure on HTTPS.
|
||||
*
|
||||
* @param string $value Value.
|
||||
* @param int $expires Expiry timestamp.
|
||||
*/
|
||||
private function send_cookie( $value, $expires ) {
|
||||
$path = wp_parse_url( home_url( '/' ), PHP_URL_PATH );
|
||||
$path = is_string( $path ) && '' !== $path ? $path : '/';
|
||||
|
||||
setcookie(
|
||||
self::STATE_COOKIE,
|
||||
$value,
|
||||
array(
|
||||
'expires' => $expires,
|
||||
'path' => $path,
|
||||
'domain' => COOKIE_DOMAIN ? COOKIE_DOMAIN : '',
|
||||
'secure' => is_ssl(),
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts the flow and shows a generic error on the login screen.
|
||||
*
|
||||
* @param string $code Error code (mapped to a translated message on the login page).
|
||||
*/
|
||||
private function fail( $code ) {
|
||||
$this->clear_state_cookie();
|
||||
wp_safe_redirect( add_query_arg( 'm365_error', rawurlencode( $code ), wp_login_url() ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes to the PHP error log when WP_DEBUG_LOG is enabled.
|
||||
*
|
||||
* @param string $message Message.
|
||||
*/
|
||||
private function log( $message ) {
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
|
||||
error_log( '[M365 Login] ' . $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps error codes to messages on the login screen.
|
||||
*
|
||||
* @param WP_Error $errors Login errors.
|
||||
* @return WP_Error
|
||||
*/
|
||||
public function login_errors( $errors ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display of a whitelisted error code.
|
||||
$code = isset( $_GET['m365_error'] ) ? sanitize_key( wp_unslash( $_GET['m365_error'] ) ) : '';
|
||||
if ( '' === $code ) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$messages = array(
|
||||
'not_configured' => __( 'Microsoft login is not configured yet.', 'm365-login' ),
|
||||
'invalid_state' => __( 'The login request expired or was invalid. Please try again.', 'm365-login' ),
|
||||
'access_denied' => __( 'Microsoft sign-in was cancelled.', 'm365-login' ),
|
||||
'provider_error' => __( 'Microsoft returned an error. Please try again.', 'm365-login' ),
|
||||
'token_exchange' => __( 'Could not complete the sign-in with Microsoft. Please try again or contact an administrator.', 'm365-login' ),
|
||||
'invalid_token' => __( 'The Microsoft sign-in could not be verified.', 'm365-login' ),
|
||||
'no_email' => __( 'Your Microsoft account did not provide an e-mail address.', 'm365-login' ),
|
||||
'domain_not_allowed' => __( 'Your e-mail domain is not allowed to sign in here.', 'm365-login' ),
|
||||
'no_user' => __( 'No WordPress account exists for your Microsoft e-mail address.', 'm365-login' ),
|
||||
'oid_mismatch' => __( 'This WordPress account is linked to a different Microsoft account. Please contact an administrator.', 'm365-login' ),
|
||||
'not_allowed' => __( 'You are not allowed to sign in with this account.', 'm365-login' ),
|
||||
);
|
||||
|
||||
if ( ! $errors instanceof WP_Error ) {
|
||||
$errors = new WP_Error();
|
||||
}
|
||||
$errors->add(
|
||||
'm365_login_' . $code,
|
||||
isset( $messages[ $code ] ) ? $messages[ $code ] : $messages['provider_error'],
|
||||
'access_denied' === $code ? 'message' : 'error'
|
||||
);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
191
includes/class-m365-login-button.php
Normal file
191
includes/class-m365-login-button.php
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
/**
|
||||
* Login page button.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Renders the "Sign in with Microsoft" button on wp-login.php.
|
||||
*/
|
||||
class M365_Login_Button {
|
||||
|
||||
/**
|
||||
* Settings.
|
||||
*
|
||||
* @var M365_Login_Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param M365_Login_Settings $settings Settings.
|
||||
*/
|
||||
public function __construct( M365_Login_Settings $settings ) {
|
||||
$this->settings = $settings;
|
||||
|
||||
add_action( 'login_enqueue_scripts', array( $this, 'enqueue' ) );
|
||||
add_filter( 'login_message', array( $this, 'render_above' ), 20 );
|
||||
add_action( 'login_footer', array( $this, 'render_below' ) );
|
||||
add_shortcode( 'm365_login_button', array( $this, 'shortcode' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the button should be shown for the current login screen.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function should_render() {
|
||||
if ( ! $this->settings->is_configured() ) {
|
||||
return false;
|
||||
}
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only routing check.
|
||||
$action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : 'login';
|
||||
$interim = ! empty( $_REQUEST['interim-login'] );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
if ( $interim || ! in_array( $action, array( '', 'login' ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Filters whether the Microsoft button is displayed on the login screen.
|
||||
*
|
||||
* @param bool $show Show the button.
|
||||
*/
|
||||
return (bool) apply_filters( 'm365_login_show_button', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues login styles and the small positioning script.
|
||||
*/
|
||||
public function enqueue() {
|
||||
if ( ! $this->should_render() ) {
|
||||
return;
|
||||
}
|
||||
wp_enqueue_style( 'm365-login', M365_LOGIN_URL . 'assets/css/login.css', array(), M365_LOGIN_VERSION );
|
||||
wp_add_inline_style( 'm365-login', $this->css_variables() );
|
||||
|
||||
if ( 'below' === $this->settings->get( 'button_position' ) ) {
|
||||
wp_enqueue_script( 'm365-login', M365_LOGIN_URL . 'assets/js/login.js', array(), M365_LOGIN_VERSION, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS custom properties derived from the settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function css_variables() {
|
||||
$s = $this->settings->all();
|
||||
return sprintf(
|
||||
'.m365-login{--m365-bg:%1$s;--m365-bg-hover:%2$s;--m365-color:%3$s;--m365-border:%4$s;--m365-radius:%5$dpx;}',
|
||||
sanitize_hex_color( $s['button_bg'] ),
|
||||
sanitize_hex_color( $s['button_bg_hover'] ),
|
||||
sanitize_hex_color( $s['button_color'] ),
|
||||
sanitize_hex_color( $s['button_border'] ),
|
||||
absint( $s['button_radius'] )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output above the form (via login_message).
|
||||
*
|
||||
* @param string $message Existing message HTML.
|
||||
* @return string
|
||||
*/
|
||||
public function render_above( $message ) {
|
||||
if ( 'above' !== $this->settings->get( 'button_position' ) || ! $this->should_render() ) {
|
||||
return $message;
|
||||
}
|
||||
return $message . $this->markup( 'above' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output below the form (moved into place by login.js).
|
||||
*/
|
||||
public function render_below() {
|
||||
if ( 'below' !== $this->settings->get( 'button_position' ) || ! $this->should_render() ) {
|
||||
return;
|
||||
}
|
||||
echo $this->markup( 'below' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- markup() escapes everything.
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode for placing the button on custom login pages.
|
||||
*
|
||||
* @param array $atts Attributes.
|
||||
* @return string
|
||||
*/
|
||||
public function shortcode( $atts ) {
|
||||
if ( ! $this->settings->is_configured() || is_user_logged_in() ) {
|
||||
return '';
|
||||
}
|
||||
$atts = shortcode_atts( array( 'redirect' => '' ), $atts, 'm365_login_button' );
|
||||
|
||||
wp_enqueue_style( 'm365-login', M365_LOGIN_URL . 'assets/css/login.css', array(), M365_LOGIN_VERSION );
|
||||
wp_add_inline_style( 'm365-login', $this->css_variables() );
|
||||
|
||||
return '<div class="m365-login m365-login--shortcode">' . $this->button( esc_url_raw( $atts['redirect'] ) ) . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Full block: divider + button.
|
||||
*
|
||||
* @param string $position 'above' or 'below'.
|
||||
* @return string
|
||||
*/
|
||||
public function markup( $position ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- passed through to the flow, validated there.
|
||||
$redirect_to = isset( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : '';
|
||||
|
||||
$divider = (string) $this->settings->get( 'divider_text' );
|
||||
$divider = '' === trim( $divider ) ? '' : '<div class="m365-login__divider" aria-hidden="true"><span>' . esc_html( $divider ) . '</span></div>';
|
||||
|
||||
$html = '<div class="m365-login m365-login--' . esc_attr( $position ) . '" id="m365-login-block">';
|
||||
$html .= 'above' === $position ? $this->button( $redirect_to ) . $divider : $divider . $this->button( $redirect_to );
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Button markup.
|
||||
*
|
||||
* @param string $redirect_to Post-login destination.
|
||||
* @return string
|
||||
*/
|
||||
public function button( $redirect_to = '' ) {
|
||||
$auth = M365_Login::instance()->auth;
|
||||
$url = $auth->start_url( $redirect_to );
|
||||
|
||||
$icon = '';
|
||||
if ( $this->settings->get( 'button_show_icon' ) ) {
|
||||
$custom = (string) $this->settings->get( 'button_icon' );
|
||||
if ( '' !== $custom && M365_Login_Settings::is_safe_image_url( $custom ) ) {
|
||||
$icon = '<img class="m365-login__icon" src="' . esc_url( $custom ) . '" alt="" width="20" height="20" loading="lazy" />';
|
||||
} else {
|
||||
$icon = self::microsoft_logo();
|
||||
}
|
||||
}
|
||||
|
||||
return '<a class="m365-login__button" href="' . esc_url( $url ) . '" rel="nofollow">'
|
||||
. $icon
|
||||
. '<span class="m365-login__label">' . esc_html( $this->settings->get( 'button_text' ) ) . '</span>'
|
||||
. '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Bundled Microsoft logo (inline SVG, four coloured squares).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function microsoft_logo() {
|
||||
return '<svg class="m365-login__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 23" width="20" height="20" aria-hidden="true" focusable="false">'
|
||||
. '<path fill="#f25022" d="M1 1h10v10H1z"/>'
|
||||
. '<path fill="#7fba00" d="M12 1h10v10H12z"/>'
|
||||
. '<path fill="#00a4ef" d="M1 12h10v10H1z"/>'
|
||||
. '<path fill="#ffb900" d="M12 12h10v10H12z"/>'
|
||||
. '</svg>';
|
||||
}
|
||||
}
|
||||
85
includes/class-m365-login-crypto.php
Normal file
85
includes/class-m365-login-crypto.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
/**
|
||||
* Symmetric encryption for secrets at rest.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* AES-256-GCM helper keyed from the WordPress salts.
|
||||
*
|
||||
* The key is derived from AUTH_KEY / SECURE_AUTH_KEY (via wp_salt()), so the
|
||||
* stored client secret is useless without access to wp-config.php.
|
||||
*/
|
||||
final class M365_Login_Crypto {
|
||||
|
||||
const PREFIX = 'm365v1:';
|
||||
const CIPHER = 'aes-256-gcm';
|
||||
|
||||
/**
|
||||
* Derives the encryption key.
|
||||
*
|
||||
* @return string 32 raw bytes.
|
||||
*/
|
||||
private static function key() {
|
||||
$material = wp_salt( 'auth' ) . '|' . wp_salt( 'secure_auth' ) . '|m365-login';
|
||||
if ( function_exists( 'hash_hkdf' ) ) {
|
||||
return hash_hkdf( 'sha256', $material, 32, 'm365-login-client-secret' );
|
||||
}
|
||||
return hash( 'sha256', $material, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether encryption is available.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function available() {
|
||||
return function_exists( 'openssl_encrypt' ) && in_array( self::CIPHER, openssl_get_cipher_methods(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a string.
|
||||
*
|
||||
* @param string $plain Plain text.
|
||||
* @return string|false
|
||||
*/
|
||||
public static function encrypt( $plain ) {
|
||||
if ( ! self::available() ) {
|
||||
return false;
|
||||
}
|
||||
$iv = random_bytes( 12 );
|
||||
$tag = '';
|
||||
$ct = openssl_encrypt( $plain, self::CIPHER, self::key(), OPENSSL_RAW_DATA, $iv, $tag, '', 16 );
|
||||
if ( false === $ct || '' === $tag ) {
|
||||
return false;
|
||||
}
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
return self::PREFIX . base64_encode( $iv . $tag . $ct );
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a string produced by encrypt().
|
||||
*
|
||||
* @param string $stored Stored value.
|
||||
* @return string|false
|
||||
*/
|
||||
public static function decrypt( $stored ) {
|
||||
if ( ! is_string( $stored ) || 0 !== strpos( $stored, self::PREFIX ) || ! self::available() ) {
|
||||
return false;
|
||||
}
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
|
||||
$raw = base64_decode( substr( $stored, strlen( self::PREFIX ) ), true );
|
||||
if ( false === $raw || strlen( $raw ) < 28 ) {
|
||||
return false;
|
||||
}
|
||||
$iv = substr( $raw, 0, 12 );
|
||||
$tag = substr( $raw, 12, 16 );
|
||||
$ct = substr( $raw, 28 );
|
||||
|
||||
$plain = openssl_decrypt( $ct, self::CIPHER, self::key(), OPENSSL_RAW_DATA, $iv, $tag );
|
||||
return false === $plain ? false : $plain;
|
||||
}
|
||||
}
|
||||
236
includes/class-m365-login-jwt.php
Normal file
236
includes/class-m365-login-jwt.php
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/**
|
||||
* ID token validation.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Verifies RS256 signed JWTs against the Microsoft JWKS.
|
||||
*/
|
||||
final class M365_Login_JWT {
|
||||
|
||||
const LEEWAY = 120; // Seconds of clock skew tolerated.
|
||||
|
||||
/**
|
||||
* Base64url decode.
|
||||
*
|
||||
* @param string $data Data.
|
||||
* @return string|false
|
||||
*/
|
||||
public static function b64url_decode( $data ) {
|
||||
$data = strtr( $data, '-_', '+/' );
|
||||
$pad = strlen( $data ) % 4;
|
||||
if ( $pad ) {
|
||||
$data .= str_repeat( '=', 4 - $pad );
|
||||
}
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
|
||||
return base64_decode( $data, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64url encode.
|
||||
*
|
||||
* @param string $data Data.
|
||||
* @return string
|
||||
*/
|
||||
public static function b64url_encode( $data ) {
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
return rtrim( strtr( base64_encode( $data ), '+/', '-_' ), '=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes and verifies a JWT.
|
||||
*
|
||||
* @param string $jwt Compact serialised token.
|
||||
* @param array $jwks JWKS document (array with 'keys').
|
||||
* @param array $expected Expected claims: 'aud', 'nonce', 'tenant' (optional GUID).
|
||||
* @return array|WP_Error Claims on success.
|
||||
*/
|
||||
public static function verify( $jwt, $jwks, $expected ) {
|
||||
$parts = explode( '.', $jwt );
|
||||
if ( 3 !== count( $parts ) ) {
|
||||
return new WP_Error( 'jwt_format', 'Malformed token.' );
|
||||
}
|
||||
|
||||
list( $h64, $p64, $s64 ) = $parts;
|
||||
|
||||
$header = json_decode( self::b64url_decode( $h64 ), true );
|
||||
$claims = json_decode( self::b64url_decode( $p64 ), true );
|
||||
$signature = self::b64url_decode( $s64 );
|
||||
|
||||
if ( ! is_array( $header ) || ! is_array( $claims ) || false === $signature ) {
|
||||
return new WP_Error( 'jwt_format', 'Malformed token.' );
|
||||
}
|
||||
|
||||
// Only RS256 is accepted; refuse "none" and anything HMAC based.
|
||||
if ( empty( $header['alg'] ) || 'RS256' !== $header['alg'] ) {
|
||||
return new WP_Error( 'jwt_alg', 'Unsupported token algorithm.' );
|
||||
}
|
||||
if ( empty( $header['kid'] ) || ! is_string( $header['kid'] ) ) {
|
||||
return new WP_Error( 'jwt_kid', 'Token has no key ID.' );
|
||||
}
|
||||
|
||||
$public_key = self::find_key( $jwks, $header['kid'] );
|
||||
if ( ! $public_key ) {
|
||||
return new WP_Error( 'jwt_unknown_kid', 'Signing key not found.' );
|
||||
}
|
||||
|
||||
$ok = openssl_verify( $h64 . '.' . $p64, $signature, $public_key, OPENSSL_ALGO_SHA256 );
|
||||
if ( 1 !== $ok ) {
|
||||
return new WP_Error( 'jwt_signature', 'Token signature is invalid.' );
|
||||
}
|
||||
|
||||
$now = time();
|
||||
|
||||
if ( empty( $claims['exp'] ) || ! is_numeric( $claims['exp'] ) || ( (int) $claims['exp'] + self::LEEWAY ) < $now ) {
|
||||
return new WP_Error( 'jwt_expired', 'Token has expired.' );
|
||||
}
|
||||
if ( isset( $claims['nbf'] ) && is_numeric( $claims['nbf'] ) && ( (int) $claims['nbf'] - self::LEEWAY ) > $now ) {
|
||||
return new WP_Error( 'jwt_nbf', 'Token is not valid yet.' );
|
||||
}
|
||||
if ( isset( $claims['iat'] ) && is_numeric( $claims['iat'] ) && ( (int) $claims['iat'] - self::LEEWAY ) > $now ) {
|
||||
return new WP_Error( 'jwt_iat', 'Token issued in the future.' );
|
||||
}
|
||||
|
||||
// Audience must be our client ID.
|
||||
$aud = isset( $claims['aud'] ) ? $claims['aud'] : null;
|
||||
if ( is_array( $aud ) ) {
|
||||
$aud_ok = in_array( $expected['aud'], $aud, true );
|
||||
} else {
|
||||
$aud_ok = is_string( $aud ) && hash_equals( $expected['aud'], $aud );
|
||||
}
|
||||
if ( ! $aud_ok ) {
|
||||
return new WP_Error( 'jwt_aud', 'Token audience mismatch.' );
|
||||
}
|
||||
|
||||
// Tenant / issuer: v2.0 issuer is https://login.microsoftonline.com/{tid}/v2.0.
|
||||
if ( empty( $claims['tid'] ) || ! is_string( $claims['tid'] ) || ! M365_Login_Settings::is_guid( $claims['tid'] ) ) {
|
||||
return new WP_Error( 'jwt_tid', 'Token has no tenant ID.' );
|
||||
}
|
||||
if ( ! empty( $expected['tenant'] ) && ! hash_equals( strtolower( $expected['tenant'] ), strtolower( $claims['tid'] ) ) ) {
|
||||
return new WP_Error( 'jwt_tenant', 'Token was issued by a different tenant.' );
|
||||
}
|
||||
$expected_iss = 'https://login.microsoftonline.com/' . strtolower( $claims['tid'] ) . '/v2.0';
|
||||
if ( empty( $claims['iss'] ) || ! is_string( $claims['iss'] ) || ! hash_equals( $expected_iss, strtolower( $claims['iss'] ) ) ) {
|
||||
return new WP_Error( 'jwt_iss', 'Token issuer mismatch.' );
|
||||
}
|
||||
|
||||
// Nonce binds the token to the login attempt.
|
||||
if ( empty( $claims['nonce'] ) || ! is_string( $claims['nonce'] ) || ! hash_equals( $expected['nonce'], $claims['nonce'] ) ) {
|
||||
return new WP_Error( 'jwt_nonce', 'Token nonce mismatch.' );
|
||||
}
|
||||
|
||||
return $claims;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a key by kid and returns an OpenSSL public key resource/object.
|
||||
*
|
||||
* @param array $jwks JWKS document.
|
||||
* @param string $kid Key ID.
|
||||
* @return mixed|null
|
||||
*/
|
||||
private static function find_key( $jwks, $kid ) {
|
||||
if ( empty( $jwks['keys'] ) || ! is_array( $jwks['keys'] ) ) {
|
||||
return null;
|
||||
}
|
||||
foreach ( $jwks['keys'] as $key ) {
|
||||
if ( ! is_array( $key ) || empty( $key['kid'] ) || ! hash_equals( (string) $key['kid'], $kid ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $key['kty'] ) && 'RSA' !== $key['kty'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $key['use'] ) && 'sig' !== $key['use'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prefer the embedded certificate, fall back to modulus/exponent.
|
||||
if ( ! empty( $key['x5c'][0] ) && is_string( $key['x5c'][0] ) ) {
|
||||
$pem = "-----BEGIN CERTIFICATE-----\n" . chunk_split( $key['x5c'][0], 64, "\n" ) . "-----END CERTIFICATE-----\n";
|
||||
$pub = openssl_pkey_get_public( $pem );
|
||||
if ( $pub ) {
|
||||
return $pub;
|
||||
}
|
||||
}
|
||||
if ( ! empty( $key['n'] ) && ! empty( $key['e'] ) ) {
|
||||
$pem = self::rsa_pem_from_components( $key['n'], $key['e'] );
|
||||
if ( $pem ) {
|
||||
$pub = openssl_pkey_get_public( $pem );
|
||||
if ( $pub ) {
|
||||
return $pub;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a PEM encoded SubjectPublicKeyInfo from JWK modulus / exponent.
|
||||
*
|
||||
* @param string $n Base64url modulus.
|
||||
* @param string $e Base64url exponent.
|
||||
* @return string|false
|
||||
*/
|
||||
private static function rsa_pem_from_components( $n, $e ) {
|
||||
$modulus = self::b64url_decode( $n );
|
||||
$exponent = self::b64url_decode( $e );
|
||||
if ( false === $modulus || false === $exponent ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$modulus = self::der_integer( $modulus );
|
||||
$exponent = self::der_integer( $exponent );
|
||||
|
||||
$rsa_key = self::der_seq( $modulus . $exponent );
|
||||
// rsaEncryption OID 1.2.840.113549.1.1.1 + NULL.
|
||||
$alg_id = self::der_seq( "\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00" );
|
||||
$bit_str = "\x03" . self::der_len( strlen( $rsa_key ) + 1 ) . "\x00" . $rsa_key;
|
||||
$spki = self::der_seq( $alg_id . $bit_str );
|
||||
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
return "-----BEGIN PUBLIC KEY-----\n" . chunk_split( base64_encode( $spki ), 64, "\n" ) . "-----END PUBLIC KEY-----\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* DER length encoding.
|
||||
*
|
||||
* @param int $len Length.
|
||||
* @return string
|
||||
*/
|
||||
private static function der_len( $len ) {
|
||||
if ( $len < 128 ) {
|
||||
return chr( $len );
|
||||
}
|
||||
$bytes = ltrim( pack( 'N', $len ), "\x00" );
|
||||
return chr( 0x80 | strlen( $bytes ) ) . $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* DER SEQUENCE.
|
||||
*
|
||||
* @param string $content Content.
|
||||
* @return string
|
||||
*/
|
||||
private static function der_seq( $content ) {
|
||||
return "\x30" . self::der_len( strlen( $content ) ) . $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* DER INTEGER (unsigned big-endian input).
|
||||
*
|
||||
* @param string $bytes Raw bytes.
|
||||
* @return string
|
||||
*/
|
||||
private static function der_integer( $bytes ) {
|
||||
$bytes = ltrim( $bytes, "\x00" );
|
||||
if ( '' === $bytes || ( ord( $bytes[0] ) & 0x80 ) ) {
|
||||
$bytes = "\x00" . $bytes;
|
||||
}
|
||||
return "\x02" . self::der_len( strlen( $bytes ) ) . $bytes;
|
||||
}
|
||||
}
|
||||
283
includes/class-m365-login-settings.php
Normal file
283
includes/class-m365-login-settings.php
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
<?php
|
||||
/**
|
||||
* Settings storage and sanitisation.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Reads, sanitises and writes plugin settings.
|
||||
*/
|
||||
class M365_Login_Settings {
|
||||
|
||||
/**
|
||||
* Cached settings.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
private $cache = null;
|
||||
|
||||
/**
|
||||
* Default settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function defaults() {
|
||||
return array(
|
||||
// Connection.
|
||||
'tenant_id' => '',
|
||||
'client_id' => '',
|
||||
'client_secret' => '', // Stored encrypted.
|
||||
'prompt' => 'select_account',
|
||||
// Security / matching.
|
||||
'upn_fallback' => 1,
|
||||
'bind_oid' => 1,
|
||||
'allowed_domains' => '',
|
||||
'remember_me' => 0,
|
||||
// Button appearance.
|
||||
'button_text' => __( 'Sign in with Microsoft', 'm365-login' ),
|
||||
'button_icon' => '', // Empty = bundled Microsoft logo.
|
||||
'button_show_icon' => 1,
|
||||
'button_bg' => '#2f2f2f',
|
||||
'button_bg_hover' => '#1a1a1a',
|
||||
'button_color' => '#ffffff',
|
||||
'button_border' => '#2f2f2f',
|
||||
'button_radius' => 4,
|
||||
'button_position' => 'below',
|
||||
'divider_text' => __( 'or', 'm365-login' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all settings merged with defaults.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
if ( null === $this->cache ) {
|
||||
$stored = get_option( M365_LOGIN_OPTION, array() );
|
||||
$this->cache = wp_parse_args( is_array( $stored ) ? $stored : array(), $this->defaults() );
|
||||
}
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single setting.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @param mixed $default Fallback.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $key, $default = null ) {
|
||||
$all = $this->all();
|
||||
return array_key_exists( $key, $all ) ? $all[ $key ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypted client secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function client_secret() {
|
||||
$enc = (string) $this->get( 'client_secret', '' );
|
||||
if ( '' === $enc ) {
|
||||
return '';
|
||||
}
|
||||
$plain = M365_Login_Crypto::decrypt( $enc );
|
||||
return is_string( $plain ) ? $plain : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the plugin has everything it needs to start a login.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_configured() {
|
||||
return '' !== $this->get( 'tenant_id' ) && '' !== $this->get( 'client_id' ) && '' !== $this->client_secret();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenant segment used in Microsoft endpoints.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function tenant() {
|
||||
$tenant = (string) $this->get( 'tenant_id', '' );
|
||||
return '' === $tenant ? 'organizations' : $tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect URI registered in Entra ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function redirect_uri() {
|
||||
if ( $this->uses_pretty_callback() ) {
|
||||
$uri = home_url( '/m365-login/callback' );
|
||||
} else {
|
||||
$uri = add_query_arg( 'm365-login', 'callback', home_url( '/' ) );
|
||||
}
|
||||
/**
|
||||
* Filters the redirect URI registered in Entra ID.
|
||||
*
|
||||
* @param string $uri Redirect URI.
|
||||
*/
|
||||
return (string) apply_filters( 'm365_login_redirect_uri', $uri );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the callback can use a path (requires rewrite rules) instead of a query argument.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uses_pretty_callback() {
|
||||
return '' !== (string) get_option( 'permalink_structure', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed e-mail domains as an array (lowercase, no leading @).
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function allowed_domains() {
|
||||
$raw = (string) $this->get( 'allowed_domains', '' );
|
||||
if ( '' === trim( $raw ) ) {
|
||||
return array();
|
||||
}
|
||||
$parts = preg_split( '/[\s,;]+/', strtolower( $raw ) );
|
||||
$out = array();
|
||||
foreach ( $parts as $p ) {
|
||||
$p = ltrim( trim( $p ), '@' );
|
||||
if ( '' !== $p ) {
|
||||
$out[] = $p;
|
||||
}
|
||||
}
|
||||
return array_values( array_unique( $out ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitises settings coming from the admin form.
|
||||
*
|
||||
* @param array $input Raw input.
|
||||
* @return array
|
||||
*/
|
||||
public function sanitize( $input ) {
|
||||
$defaults = $this->defaults();
|
||||
$current = $this->all();
|
||||
$input = is_array( $input ) ? $input : array();
|
||||
$out = $current;
|
||||
|
||||
// Tenant: GUID or one of the well-known aliases.
|
||||
$tenant = isset( $input['tenant_id'] ) ? trim( sanitize_text_field( wp_unslash( $input['tenant_id'] ) ) ) : '';
|
||||
$tenant = strtolower( $tenant );
|
||||
if ( '' !== $tenant && ! self::is_valid_tenant( $tenant ) ) {
|
||||
add_settings_error( M365_LOGIN_OPTION, 'tenant_id', __( 'The tenant ID must be a GUID (e.g. 1a2b3c4d-…) or one of "organizations", "common", "consumers".', 'm365-login' ) );
|
||||
$tenant = $current['tenant_id'];
|
||||
}
|
||||
$out['tenant_id'] = $tenant;
|
||||
|
||||
// Client ID: GUID.
|
||||
$client_id = isset( $input['client_id'] ) ? trim( sanitize_text_field( wp_unslash( $input['client_id'] ) ) ) : '';
|
||||
if ( '' !== $client_id && ! self::is_guid( $client_id ) ) {
|
||||
add_settings_error( M365_LOGIN_OPTION, 'client_id', __( 'The application (client) ID must be a GUID.', 'm365-login' ) );
|
||||
$client_id = $current['client_id'];
|
||||
}
|
||||
$out['client_id'] = strtolower( $client_id );
|
||||
|
||||
// Client secret: only replaced when a new value was entered.
|
||||
$secret_input = isset( $input['client_secret'] ) ? (string) wp_unslash( $input['client_secret'] ) : '';
|
||||
$secret_input = trim( $secret_input );
|
||||
if ( ! empty( $input['client_secret_clear'] ) ) {
|
||||
$out['client_secret'] = '';
|
||||
} elseif ( '' !== $secret_input ) {
|
||||
if ( strlen( $secret_input ) > 512 || preg_match( '/[\x00-\x1F\x7F]/', $secret_input ) ) {
|
||||
add_settings_error( M365_LOGIN_OPTION, 'client_secret', __( 'The client secret contains invalid characters.', 'm365-login' ) );
|
||||
} else {
|
||||
$enc = M365_Login_Crypto::encrypt( $secret_input );
|
||||
if ( false === $enc ) {
|
||||
add_settings_error( M365_LOGIN_OPTION, 'client_secret', __( 'The client secret could not be encrypted. Is the OpenSSL extension available?', 'm365-login' ) );
|
||||
} else {
|
||||
$out['client_secret'] = $enc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$prompt = isset( $input['prompt'] ) ? sanitize_key( $input['prompt'] ) : '';
|
||||
$out['prompt'] = in_array( $prompt, array( 'none', 'select_account', 'login' ), true ) ? $prompt : 'none';
|
||||
|
||||
$out['upn_fallback'] = empty( $input['upn_fallback'] ) ? 0 : 1;
|
||||
$out['bind_oid'] = empty( $input['bind_oid'] ) ? 0 : 1;
|
||||
$out['remember_me'] = empty( $input['remember_me'] ) ? 0 : 1;
|
||||
|
||||
$domains = isset( $input['allowed_domains'] ) ? sanitize_textarea_field( wp_unslash( $input['allowed_domains'] ) ) : '';
|
||||
$domains = preg_replace( '/[^a-z0-9.\-@,;\s]/i', '', $domains );
|
||||
$out['allowed_domains'] = trim( (string) $domains );
|
||||
|
||||
// Button.
|
||||
$text = isset( $input['button_text'] ) ? sanitize_text_field( wp_unslash( $input['button_text'] ) ) : '';
|
||||
$out['button_text'] = '' === trim( $text ) ? $defaults['button_text'] : mb_substr( $text, 0, 80 );
|
||||
|
||||
$icon = isset( $input['button_icon'] ) ? esc_url_raw( trim( wp_unslash( $input['button_icon'] ) ) ) : '';
|
||||
$out['button_icon'] = self::is_safe_image_url( $icon ) ? $icon : '';
|
||||
|
||||
$out['button_show_icon'] = empty( $input['button_show_icon'] ) ? 0 : 1;
|
||||
|
||||
foreach ( array( 'button_bg', 'button_bg_hover', 'button_color', 'button_border' ) as $color_key ) {
|
||||
$color = isset( $input[ $color_key ] ) ? sanitize_hex_color( trim( wp_unslash( $input[ $color_key ] ) ) ) : '';
|
||||
$out[ $color_key ] = $color ? $color : $defaults[ $color_key ];
|
||||
}
|
||||
|
||||
$radius = isset( $input['button_radius'] ) ? absint( $input['button_radius'] ) : $defaults['button_radius'];
|
||||
$out['button_radius'] = min( 50, $radius );
|
||||
|
||||
$position = isset( $input['button_position'] ) ? sanitize_key( $input['button_position'] ) : 'below';
|
||||
$out['button_position'] = in_array( $position, array( 'above', 'below' ), true ) ? $position : 'below';
|
||||
|
||||
$divider = isset( $input['divider_text'] ) ? sanitize_text_field( wp_unslash( $input['divider_text'] ) ) : '';
|
||||
$out['divider_text'] = mb_substr( $divider, 0, 40 );
|
||||
|
||||
$this->cache = null;
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a GUID.
|
||||
*
|
||||
* @param string $value Value.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_guid( $value ) {
|
||||
return (bool) preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a tenant identifier.
|
||||
*
|
||||
* @param string $value Value.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_valid_tenant( $value ) {
|
||||
return self::is_guid( $value ) || in_array( $value, array( 'organizations', 'common', 'consumers' ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Only allows http(s) image URLs with a known image extension.
|
||||
*
|
||||
* @param string $url URL.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_safe_image_url( $url ) {
|
||||
if ( '' === $url ) {
|
||||
return false;
|
||||
}
|
||||
$parts = wp_parse_url( $url );
|
||||
if ( empty( $parts['scheme'] ) || ! in_array( strtolower( $parts['scheme'] ), array( 'http', 'https' ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
$path = isset( $parts['path'] ) ? strtolower( $parts['path'] ) : '';
|
||||
return (bool) preg_match( '/\.(png|jpe?g|gif|svg|webp)$/', $path );
|
||||
}
|
||||
}
|
||||
125
includes/class-m365-login.php
Normal file
125
includes/class-m365-login.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin bootstrap.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Wires the individual components together.
|
||||
*/
|
||||
final class M365_Login {
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*
|
||||
* @var M365_Login|null
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Settings component.
|
||||
*
|
||||
* @var M365_Login_Settings
|
||||
*/
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Authentication component.
|
||||
*
|
||||
* @var M365_Login_Auth
|
||||
*/
|
||||
public $auth;
|
||||
|
||||
/**
|
||||
* Login button component.
|
||||
*
|
||||
* @var M365_Login_Button
|
||||
*/
|
||||
public $button;
|
||||
|
||||
/**
|
||||
* Admin component.
|
||||
*
|
||||
* @var M365_Login_Admin|null
|
||||
*/
|
||||
public $admin = null;
|
||||
|
||||
/**
|
||||
* Returns the singleton.
|
||||
*
|
||||
* @return M365_Login
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
private function __construct() {
|
||||
add_action( 'init', array( $this, 'load_textdomain' ) );
|
||||
|
||||
$this->settings = new M365_Login_Settings();
|
||||
$this->auth = new M365_Login_Auth( $this->settings );
|
||||
$this->button = new M365_Login_Button( $this->settings );
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->admin = new M365_Login_Admin( $this->settings, $this->auth );
|
||||
}
|
||||
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( M365_LOGIN_FILE ), array( $this, 'action_links' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads bundled translations.
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
load_plugin_textdomain( 'm365-login', false, dirname( plugin_basename( M365_LOGIN_FILE ) ) . '/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a "Settings" link on the plugins screen.
|
||||
*
|
||||
* @param string[] $links Existing links.
|
||||
* @return string[]
|
||||
*/
|
||||
public function action_links( $links ) {
|
||||
$url = admin_url( 'options-general.php?page=m365-login' );
|
||||
array_unshift( $links, '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Settings', 'm365-login' ) . '</a>' );
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activation hook: seed defaults and check requirements.
|
||||
*/
|
||||
public static function activate() {
|
||||
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
|
||||
deactivate_plugins( plugin_basename( M365_LOGIN_FILE ) );
|
||||
wp_die(
|
||||
esc_html__( 'M365 Login requires PHP 7.4 or newer.', 'm365-login' ),
|
||||
esc_html__( 'Plugin activation failed', 'm365-login' ),
|
||||
array( 'back_link' => true )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'openssl_encrypt' ) ) {
|
||||
deactivate_plugins( plugin_basename( M365_LOGIN_FILE ) );
|
||||
wp_die(
|
||||
esc_html__( 'M365 Login requires the PHP OpenSSL extension (needed to verify Microsoft token signatures and to encrypt the client secret).', 'm365-login' ),
|
||||
esc_html__( 'Plugin activation failed', 'm365-login' ),
|
||||
array( 'back_link' => true )
|
||||
);
|
||||
}
|
||||
|
||||
$settings = new M365_Login_Settings();
|
||||
if ( false === get_option( M365_LOGIN_OPTION, false ) ) {
|
||||
add_option( M365_LOGIN_OPTION, $settings->defaults(), '', 'no' );
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
languages/m365-login-de_DE.mo
Normal file
BIN
languages/m365-login-de_DE.mo
Normal file
Binary file not shown.
460
languages/m365-login-de_DE.po
Normal file
460
languages/m365-login-de_DE.po
Normal file
|
|
@ -0,0 +1,460 @@
|
|||
# German translation for M365 Login.
|
||||
# This file is distributed under the GPL-2.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: M365 Login 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/friloo/wp-m365-login/issues\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-09-22T00:00:00+00:00\n"
|
||||
"PO-Revision-Date: 2026-09-22 12:00+0000\n"
|
||||
"Last-Translator: friloo\n"
|
||||
"Language-Team: German\n"
|
||||
"Language: de_DE\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Generator: bin/make-pot.py\n"
|
||||
"X-Domain: m365-login\n"
|
||||
|
||||
#: includes/class-m365-login-admin.php:63 includes/class-m365-login-admin.php:64 includes/class-m365-login-admin.php:203
|
||||
msgid "M365 Login"
|
||||
msgstr "M365 Login"
|
||||
|
||||
#: includes/class-m365-login-admin.php:102
|
||||
msgid "M365 Login is active but not connected to Microsoft Entra ID yet."
|
||||
msgstr "M365 Login ist aktiv, aber noch nicht mit Microsoft Entra ID verbunden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:104
|
||||
msgid "Open the settings"
|
||||
msgstr "Einstellungen öffnen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:132
|
||||
msgid "Choose button icon"
|
||||
msgstr "Button-Icon auswählen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:133
|
||||
msgid "Use this icon"
|
||||
msgstr "Dieses Icon verwenden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:134
|
||||
msgid "Copied!"
|
||||
msgstr "Kopiert!"
|
||||
|
||||
#: includes/class-m365-login-admin.php:135 includes/class-m365-login-admin.php:427
|
||||
msgid "Copy"
|
||||
msgstr "Kopieren"
|
||||
|
||||
#: includes/class-m365-login-admin.php:136
|
||||
msgid "Testing…"
|
||||
msgstr "Wird geprüft …"
|
||||
|
||||
#: includes/class-m365-login-admin.php:137
|
||||
msgid "The tenant could not be reached. Check the tenant ID and the server’s outgoing connections."
|
||||
msgstr "Der Tenant ist nicht erreichbar. Bitte Tenant-ID und ausgehende Verbindungen des Servers prüfen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:149
|
||||
msgid "You are not allowed to do this."
|
||||
msgstr "Dafür fehlt die Berechtigung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:154
|
||||
msgid "Please enter a valid tenant ID first."
|
||||
msgstr "Bitte zuerst eine gültige Tenant-ID eingeben."
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:168
|
||||
msgid "Microsoft answered with HTTP %d. Is the tenant ID correct?"
|
||||
msgstr "Microsoft hat mit HTTP %d geantwortet. Ist die Tenant-ID korrekt?"
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:177
|
||||
msgid "Tenant reachable. The OpenID configuration was loaded successfully."
|
||||
msgstr "Tenant erreichbar. Die OpenID-Konfiguration wurde erfolgreich geladen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:187
|
||||
msgid "You are not allowed to access this page."
|
||||
msgstr "Für diese Seite fehlt die Berechtigung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:204
|
||||
msgid "Let existing users sign in with their Microsoft 365 / Entra ID account."
|
||||
msgstr "Bestehende Benutzer melden sich mit ihrem Microsoft 365 / Entra ID-Konto an."
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Connected"
|
||||
msgstr "Verbunden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Setup incomplete"
|
||||
msgstr "Einrichtung unvollständig"
|
||||
|
||||
#: includes/class-m365-login-admin.php:217
|
||||
msgid "Connection"
|
||||
msgstr "Verbindung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:218
|
||||
msgid "Button"
|
||||
msgstr "Button"
|
||||
|
||||
#: includes/class-m365-login-admin.php:219
|
||||
msgid "Security"
|
||||
msgstr "Sicherheit"
|
||||
|
||||
#: includes/class-m365-login-admin.php:228
|
||||
msgid "Microsoft Entra ID app registration"
|
||||
msgstr "App-Registrierung in Microsoft Entra ID"
|
||||
|
||||
#: includes/class-m365-login-admin.php:229
|
||||
msgid "Enter the values from your app registration in the Microsoft Entra admin center."
|
||||
msgstr "Trage hier die Werte aus deiner App-Registrierung im Microsoft Entra Admin Center ein."
|
||||
|
||||
#: includes/class-m365-login-admin.php:232
|
||||
msgid "Directory (tenant) ID"
|
||||
msgstr "Verzeichnis-ID (Mandant/Tenant)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:235
|
||||
msgid "Test tenant"
|
||||
msgstr "Tenant testen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:237
|
||||
msgid "Recommended: the GUID of your tenant. Only sign-ins from this tenant are accepted. \"organizations\" allows any work or school account."
|
||||
msgstr "Empfohlen: die GUID deines Tenants. Dann werden nur Anmeldungen aus diesem Tenant akzeptiert. „organizations“ erlaubt beliebige Geschäfts-, Schul- oder Unikonten."
|
||||
|
||||
#: includes/class-m365-login-admin.php:242
|
||||
msgid "Application (client) ID"
|
||||
msgstr "Anwendungs-ID (Client)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:247
|
||||
msgid "Client secret"
|
||||
msgstr "Geheimer Clientschlüssel (Client Secret)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "•••••••••••• (stored, leave empty to keep)"
|
||||
msgstr "•••••••••••• (gespeichert – leer lassen, um zu behalten)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "Paste the secret value"
|
||||
msgstr "Wert des Secrets einfügen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:250
|
||||
msgid "Show secret"
|
||||
msgstr "Secret anzeigen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:255
|
||||
msgid "Remove the stored secret"
|
||||
msgstr "Gespeichertes Secret entfernen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:258
|
||||
msgid "Stored encrypted (AES-256-GCM, key derived from your WordPress salts) and never displayed again. Client secrets expire – note the expiry date in Entra ID."
|
||||
msgstr "Wird verschlüsselt gespeichert (AES-256-GCM, Schlüssel aus den WordPress-Salts abgeleitet) und nie wieder angezeigt. Client Secrets laufen ab – Ablaufdatum in Entra ID notieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:262
|
||||
msgid "Account prompt"
|
||||
msgstr "Kontoauswahl"
|
||||
|
||||
#: includes/class-m365-login-admin.php:264
|
||||
msgid "Always let the user pick an account (recommended)"
|
||||
msgstr "Benutzer wählt immer ein Konto aus (empfohlen)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:265
|
||||
msgid "Use the current Microsoft session if available"
|
||||
msgstr "Vorhandene Microsoft-Sitzung verwenden, falls vorhanden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:266
|
||||
msgid "Always require re-entering credentials"
|
||||
msgstr "Immer erneute Eingabe der Anmeldedaten verlangen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:275
|
||||
msgid "Appearance"
|
||||
msgstr "Darstellung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:278
|
||||
msgid "Live preview"
|
||||
msgstr "Live-Vorschau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:292
|
||||
msgid "Button text"
|
||||
msgstr "Button-Text"
|
||||
|
||||
#: includes/class-m365-login-admin.php:296
|
||||
msgid "Divider text"
|
||||
msgstr "Trennlinien-Text"
|
||||
|
||||
#: includes/class-m365-login-admin.php:298
|
||||
msgid "Leave empty to hide the divider line."
|
||||
msgstr "Leer lassen, um die Trennlinie auszublenden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:303
|
||||
msgid "Icon"
|
||||
msgstr "Icon"
|
||||
|
||||
#: includes/class-m365-login-admin.php:306
|
||||
msgid "Show an icon on the button"
|
||||
msgstr "Icon auf dem Button anzeigen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:317
|
||||
msgid "Default: Microsoft logo"
|
||||
msgstr "Standard: Microsoft-Logo"
|
||||
|
||||
#: includes/class-m365-login-admin.php:319
|
||||
msgid "Choose from media library"
|
||||
msgstr "Aus Mediathek wählen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:320
|
||||
msgid "Use Microsoft logo"
|
||||
msgstr "Microsoft-Logo verwenden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:322
|
||||
msgid "PNG, SVG, JPG or WebP. Square images (e.g. 64×64 px) work best."
|
||||
msgstr "PNG, SVG, JPG oder WebP. Quadratische Bilder (z. B. 64×64 px) eignen sich am besten."
|
||||
|
||||
#: includes/class-m365-login-admin.php:330
|
||||
msgid "Background"
|
||||
msgstr "Hintergrund"
|
||||
|
||||
#: includes/class-m365-login-admin.php:331
|
||||
msgid "Background (hover)"
|
||||
msgstr "Hintergrund (Hover)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:332
|
||||
msgid "Text colour"
|
||||
msgstr "Textfarbe"
|
||||
|
||||
#: includes/class-m365-login-admin.php:333
|
||||
msgid "Border"
|
||||
msgstr "Rahmen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:346
|
||||
msgid "Corner radius"
|
||||
msgstr "Eckenradius"
|
||||
|
||||
#: includes/class-m365-login-admin.php:350
|
||||
msgid "Position on the login page"
|
||||
msgstr "Position auf der Login-Seite"
|
||||
|
||||
#: includes/class-m365-login-admin.php:352
|
||||
msgid "Below the login form"
|
||||
msgstr "Unter dem Login-Formular"
|
||||
|
||||
#: includes/class-m365-login-admin.php:353
|
||||
msgid "Above the login form"
|
||||
msgstr "Über dem Login-Formular"
|
||||
|
||||
#: includes/class-m365-login-admin.php:359
|
||||
msgid "Quick presets"
|
||||
msgstr "Schnellauswahl"
|
||||
|
||||
#: includes/class-m365-login-admin.php:360
|
||||
msgid "Microsoft dark"
|
||||
msgstr "Microsoft dunkel"
|
||||
|
||||
#: includes/class-m365-login-admin.php:361
|
||||
msgid "Microsoft light"
|
||||
msgstr "Microsoft hell"
|
||||
|
||||
#: includes/class-m365-login-admin.php:362
|
||||
msgid "Azure blue"
|
||||
msgstr "Azure-Blau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:363
|
||||
msgid "WordPress blue"
|
||||
msgstr "WordPress-Blau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:371
|
||||
msgid "User matching & hardening"
|
||||
msgstr "Benutzerzuordnung & Härtung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:372
|
||||
msgid "Users are never created automatically. A Microsoft sign-in only succeeds when a WordPress user with the same e-mail address already exists."
|
||||
msgstr "Benutzer werden nie automatisch angelegt. Eine Microsoft-Anmeldung gelingt nur, wenn bereits ein WordPress-Benutzer mit derselben E-Mail-Adresse existiert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:377
|
||||
msgid "Bind WordPress accounts to the Microsoft object ID"
|
||||
msgstr "WordPress-Konten an die Microsoft-Objekt-ID binden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:378
|
||||
msgid "On first sign-in the immutable Microsoft object ID is stored with the user. Later sign-ins with the same e-mail but a different Microsoft identity are rejected. Strongly recommended."
|
||||
msgstr "Bei der ersten Anmeldung wird die unveränderliche Microsoft-Objekt-ID am Benutzer gespeichert. Spätere Anmeldungen mit gleicher E-Mail, aber anderer Microsoft-Identität werden abgelehnt. Dringend empfohlen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:385
|
||||
msgid "Fall back to the user principal name (UPN)"
|
||||
msgstr "Auf den User Principal Name (UPN) zurückgreifen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:386
|
||||
msgid "If the token contains no \"email\" claim, use the UPN (e.g. jane@contoso.com) when it is a valid e-mail address. Usually required for work accounts."
|
||||
msgstr "Enthält das Token keinen „email“-Claim, wird der UPN (z. B. jane@contoso.com) verwendet, sofern er eine gültige E-Mail-Adresse ist. Für Geschäftskonten meist erforderlich."
|
||||
|
||||
#: includes/class-m365-login-admin.php:393
|
||||
msgid "Keep users signed in (\"Remember me\")"
|
||||
msgstr "Benutzer angemeldet lassen („Angemeldet bleiben“)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:394
|
||||
msgid "Issues a 14-day WordPress session instead of a browser session."
|
||||
msgstr "Erstellt eine 14-tägige WordPress-Sitzung statt einer Browser-Sitzung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:399
|
||||
msgid "Allowed e-mail domains (optional)"
|
||||
msgstr "Erlaubte E-Mail-Domains (optional)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:401
|
||||
msgid "One or more domains separated by commas or new lines. Leave empty to allow any domain of your tenant."
|
||||
msgstr "Eine oder mehrere Domains, getrennt durch Kommas oder Zeilenumbrüche. Leer lassen, um alle Domains des Tenants zuzulassen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:406
|
||||
msgid "What the plugin does to keep sign-ins safe"
|
||||
msgstr "So schützt das Plugin die Anmeldung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:408
|
||||
msgid "OpenID Connect authorization code flow with PKCE (S256) – no tokens ever pass through the browser."
|
||||
msgstr "OpenID Connect Authorization Code Flow mit PKCE (S256) – Tokens laufen nie durch den Browser."
|
||||
|
||||
#: includes/class-m365-login-admin.php:409
|
||||
msgid "Single-use state and nonce values bound to the browser via an HttpOnly cookie (CSRF and replay protection)."
|
||||
msgstr "Einmalige State- und Nonce-Werte, per HttpOnly-Cookie an den Browser gebunden (CSRF- und Replay-Schutz)."
|
||||
|
||||
#: includes/class-m365-login-admin.php:410
|
||||
msgid "ID token signature verified against Microsoft’s published signing keys; issuer, audience, tenant, expiry and nonce are checked."
|
||||
msgstr "Signatur des ID-Tokens wird gegen Microsofts veröffentlichte Signaturschlüssel geprüft; Issuer, Audience, Tenant, Ablauf und Nonce werden kontrolliert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:411
|
||||
msgid "Client secret encrypted at rest; no accounts are created, no passwords are changed."
|
||||
msgstr "Client Secret verschlüsselt gespeichert; es werden keine Konten angelegt und keine Passwörter geändert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:417
|
||||
msgid "Save changes"
|
||||
msgstr "Änderungen speichern"
|
||||
|
||||
#: includes/class-m365-login-admin.php:423
|
||||
msgid "Redirect URI"
|
||||
msgstr "Umleitungs-URI (Redirect URI)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:424
|
||||
msgid "Register this URI in your app registration under Authentication → Web → Redirect URIs:"
|
||||
msgstr "Diese URI in der App-Registrierung unter Authentifizierung → Web → Umleitungs-URIs eintragen:"
|
||||
|
||||
#: includes/class-m365-login-admin.php:430
|
||||
msgid "Plain permalinks are active, so the callback uses a query string. If you enable pretty permalinks later, the redirect URI changes and must be updated in Entra ID."
|
||||
msgstr "Einfache Permalinks sind aktiv, daher verwendet der Callback einen Query-String. Werden später sprechende Permalinks aktiviert, ändert sich die Umleitungs-URI und muss in Entra ID angepasst werden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:433
|
||||
msgid "Your site does not use HTTPS. Microsoft only accepts http:// redirect URIs for localhost; production sites must use HTTPS."
|
||||
msgstr "Diese Website nutzt kein HTTPS. Microsoft akzeptiert http://-Umleitungs-URIs nur für localhost; produktive Websites benötigen HTTPS."
|
||||
|
||||
#: includes/class-m365-login-admin.php:438
|
||||
msgid "Setup in 5 steps"
|
||||
msgstr "Einrichtung in 5 Schritten"
|
||||
|
||||
#: includes/class-m365-login-admin.php:440
|
||||
msgid "Open the Microsoft Entra admin center → App registrations → New registration."
|
||||
msgstr "Microsoft Entra Admin Center öffnen → App-Registrierungen → Neue Registrierung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:441
|
||||
msgid "Choose \"Accounts in this organizational directory only\", set the platform to Web and paste the redirect URI above."
|
||||
msgstr "„Nur Konten in diesem Organisationsverzeichnis“ wählen, Plattform „Web“ auswählen und die Umleitungs-URI von oben einfügen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:442
|
||||
msgid "Copy the Application (client) ID and Directory (tenant) ID from the overview page."
|
||||
msgstr "Anwendungs-ID (Client) und Verzeichnis-ID (Mandant) von der Übersichtsseite kopieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:443
|
||||
msgid "Under Certificates & secrets create a client secret and copy its value (not the ID)."
|
||||
msgstr "Unter „Zertifikate & Geheimnisse“ einen geheimen Clientschlüssel erstellen und dessen Wert (nicht die ID) kopieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:444
|
||||
msgid "Under Token configuration add the optional claim \"email\" for ID tokens (recommended), then save this page."
|
||||
msgstr "Unter „Tokenkonfiguration“ den optionalen Anspruch „email“ für ID-Tokens hinzufügen (empfohlen), dann diese Seite speichern."
|
||||
|
||||
#: includes/class-m365-login-admin.php:446
|
||||
msgid "Required API permission: openid, profile, email (delegated) – granted by default."
|
||||
msgstr "Benötigte API-Berechtigungen: openid, profile, email (delegiert) – standardmäßig vorhanden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:450
|
||||
msgid "Shortcode"
|
||||
msgstr "Shortcode"
|
||||
|
||||
#: includes/class-m365-login-admin.php:451
|
||||
msgid "Place the button on a custom login page:"
|
||||
msgstr "Button auf einer eigenen Login-Seite platzieren:"
|
||||
|
||||
#: includes/class-m365-login-auth.php:593
|
||||
msgid "Microsoft login is not configured yet."
|
||||
msgstr "Die Microsoft-Anmeldung ist noch nicht eingerichtet."
|
||||
|
||||
#: includes/class-m365-login-auth.php:594
|
||||
msgid "The login request expired or was invalid. Please try again."
|
||||
msgstr "Die Anmeldeanfrage ist abgelaufen oder ungültig. Bitte erneut versuchen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:595
|
||||
msgid "Microsoft sign-in was cancelled."
|
||||
msgstr "Die Microsoft-Anmeldung wurde abgebrochen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:596
|
||||
msgid "Microsoft returned an error. Please try again."
|
||||
msgstr "Microsoft hat einen Fehler gemeldet. Bitte erneut versuchen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:597
|
||||
msgid "Could not complete the sign-in with Microsoft. Please try again or contact an administrator."
|
||||
msgstr "Die Anmeldung über Microsoft konnte nicht abgeschlossen werden. Bitte erneut versuchen oder einen Administrator kontaktieren."
|
||||
|
||||
#: includes/class-m365-login-auth.php:598
|
||||
msgid "The Microsoft sign-in could not be verified."
|
||||
msgstr "Die Microsoft-Anmeldung konnte nicht verifiziert werden."
|
||||
|
||||
#: includes/class-m365-login-auth.php:599
|
||||
msgid "Your Microsoft account did not provide an e-mail address."
|
||||
msgstr "Das Microsoft-Konto hat keine E-Mail-Adresse übermittelt."
|
||||
|
||||
#: includes/class-m365-login-auth.php:600
|
||||
msgid "Your e-mail domain is not allowed to sign in here."
|
||||
msgstr "Diese E-Mail-Domain ist hier nicht zur Anmeldung zugelassen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:601
|
||||
msgid "No WordPress account exists for your Microsoft e-mail address."
|
||||
msgstr "Für die E-Mail-Adresse des Microsoft-Kontos existiert kein WordPress-Konto."
|
||||
|
||||
#: includes/class-m365-login-auth.php:602
|
||||
msgid "This WordPress account is linked to a different Microsoft account. Please contact an administrator."
|
||||
msgstr "Dieses WordPress-Konto ist mit einem anderen Microsoft-Konto verknüpft. Bitte einen Administrator kontaktieren."
|
||||
|
||||
#: includes/class-m365-login-auth.php:603
|
||||
msgid "You are not allowed to sign in with this account."
|
||||
msgstr "Die Anmeldung mit diesem Konto ist nicht erlaubt."
|
||||
|
||||
#: includes/class-m365-login-settings.php:40
|
||||
msgid "Sign in with Microsoft"
|
||||
msgstr "Login mit Microsoft"
|
||||
|
||||
#: includes/class-m365-login-settings.php:49
|
||||
msgid "or"
|
||||
msgstr "oder"
|
||||
|
||||
#: includes/class-m365-login-settings.php:176
|
||||
msgid "The tenant ID must be a GUID (e.g. 1a2b3c4d-…) or one of \"organizations\", \"common\", \"consumers\"."
|
||||
msgstr "Die Tenant-ID muss eine GUID (z. B. 1a2b3c4d-…) oder einer der Werte „organizations“, „common“, „consumers“ sein."
|
||||
|
||||
#: includes/class-m365-login-settings.php:184
|
||||
msgid "The application (client) ID must be a GUID."
|
||||
msgstr "Die Anwendungs-ID (Client) muss eine GUID sein."
|
||||
|
||||
#: includes/class-m365-login-settings.php:196
|
||||
msgid "The client secret contains invalid characters."
|
||||
msgstr "Das Client Secret enthält ungültige Zeichen."
|
||||
|
||||
#: includes/class-m365-login-settings.php:200
|
||||
msgid "The client secret could not be encrypted. Is the OpenSSL extension available?"
|
||||
msgstr "Das Client Secret konnte nicht verschlüsselt werden. Ist die OpenSSL-Erweiterung verfügbar?"
|
||||
|
||||
#: includes/class-m365-login.php:94
|
||||
msgid "Settings"
|
||||
msgstr "Einstellungen"
|
||||
|
||||
#: includes/class-m365-login.php:105
|
||||
msgid "M365 Login requires PHP 7.4 or newer."
|
||||
msgstr "M365 Login benötigt PHP 7.4 oder neuer."
|
||||
|
||||
#: includes/class-m365-login.php:106 includes/class-m365-login.php:115
|
||||
msgid "Plugin activation failed"
|
||||
msgstr "Plugin-Aktivierung fehlgeschlagen"
|
||||
|
||||
#: includes/class-m365-login.php:114
|
||||
msgid "M365 Login requires the PHP OpenSSL extension (needed to verify Microsoft token signatures and to encrypt the client secret)."
|
||||
msgstr "M365 Login benötigt die PHP-Erweiterung OpenSSL (zur Prüfung der Microsoft-Token-Signaturen und zur Verschlüsselung des Client Secrets)."
|
||||
|
||||
BIN
languages/m365-login-de_DE_formal.mo
Normal file
BIN
languages/m365-login-de_DE_formal.mo
Normal file
Binary file not shown.
460
languages/m365-login-de_DE_formal.po
Normal file
460
languages/m365-login-de_DE_formal.po
Normal file
|
|
@ -0,0 +1,460 @@
|
|||
# German translation for M365 Login.
|
||||
# This file is distributed under the GPL-2.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: M365 Login 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/friloo/wp-m365-login/issues\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-09-22T00:00:00+00:00\n"
|
||||
"PO-Revision-Date: 2026-09-22 12:00+0000\n"
|
||||
"Last-Translator: friloo\n"
|
||||
"Language-Team: German\n"
|
||||
"Language: de_DE_formal\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Generator: bin/make-pot.py\n"
|
||||
"X-Domain: m365-login\n"
|
||||
|
||||
#: includes/class-m365-login-admin.php:63 includes/class-m365-login-admin.php:64 includes/class-m365-login-admin.php:203
|
||||
msgid "M365 Login"
|
||||
msgstr "M365 Login"
|
||||
|
||||
#: includes/class-m365-login-admin.php:102
|
||||
msgid "M365 Login is active but not connected to Microsoft Entra ID yet."
|
||||
msgstr "M365 Login ist aktiv, aber noch nicht mit Microsoft Entra ID verbunden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:104
|
||||
msgid "Open the settings"
|
||||
msgstr "Einstellungen öffnen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:132
|
||||
msgid "Choose button icon"
|
||||
msgstr "Button-Icon auswählen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:133
|
||||
msgid "Use this icon"
|
||||
msgstr "Dieses Icon verwenden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:134
|
||||
msgid "Copied!"
|
||||
msgstr "Kopiert!"
|
||||
|
||||
#: includes/class-m365-login-admin.php:135 includes/class-m365-login-admin.php:427
|
||||
msgid "Copy"
|
||||
msgstr "Kopieren"
|
||||
|
||||
#: includes/class-m365-login-admin.php:136
|
||||
msgid "Testing…"
|
||||
msgstr "Wird geprüft …"
|
||||
|
||||
#: includes/class-m365-login-admin.php:137
|
||||
msgid "The tenant could not be reached. Check the tenant ID and the server’s outgoing connections."
|
||||
msgstr "Der Tenant ist nicht erreichbar. Bitte Tenant-ID und ausgehende Verbindungen des Servers prüfen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:149
|
||||
msgid "You are not allowed to do this."
|
||||
msgstr "Dafür fehlt die Berechtigung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:154
|
||||
msgid "Please enter a valid tenant ID first."
|
||||
msgstr "Bitte zuerst eine gültige Tenant-ID eingeben."
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:168
|
||||
msgid "Microsoft answered with HTTP %d. Is the tenant ID correct?"
|
||||
msgstr "Microsoft hat mit HTTP %d geantwortet. Ist die Tenant-ID korrekt?"
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:177
|
||||
msgid "Tenant reachable. The OpenID configuration was loaded successfully."
|
||||
msgstr "Tenant erreichbar. Die OpenID-Konfiguration wurde erfolgreich geladen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:187
|
||||
msgid "You are not allowed to access this page."
|
||||
msgstr "Für diese Seite fehlt die Berechtigung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:204
|
||||
msgid "Let existing users sign in with their Microsoft 365 / Entra ID account."
|
||||
msgstr "Bestehende Benutzer melden sich mit ihrem Microsoft 365 / Entra ID-Konto an."
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Connected"
|
||||
msgstr "Verbunden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Setup incomplete"
|
||||
msgstr "Einrichtung unvollständig"
|
||||
|
||||
#: includes/class-m365-login-admin.php:217
|
||||
msgid "Connection"
|
||||
msgstr "Verbindung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:218
|
||||
msgid "Button"
|
||||
msgstr "Button"
|
||||
|
||||
#: includes/class-m365-login-admin.php:219
|
||||
msgid "Security"
|
||||
msgstr "Sicherheit"
|
||||
|
||||
#: includes/class-m365-login-admin.php:228
|
||||
msgid "Microsoft Entra ID app registration"
|
||||
msgstr "App-Registrierung in Microsoft Entra ID"
|
||||
|
||||
#: includes/class-m365-login-admin.php:229
|
||||
msgid "Enter the values from your app registration in the Microsoft Entra admin center."
|
||||
msgstr "Tragen Sie hier die Werte aus Ihrer App-Registrierung im Microsoft Entra Admin Center ein."
|
||||
|
||||
#: includes/class-m365-login-admin.php:232
|
||||
msgid "Directory (tenant) ID"
|
||||
msgstr "Verzeichnis-ID (Mandant/Tenant)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:235
|
||||
msgid "Test tenant"
|
||||
msgstr "Tenant testen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:237
|
||||
msgid "Recommended: the GUID of your tenant. Only sign-ins from this tenant are accepted. \"organizations\" allows any work or school account."
|
||||
msgstr "Empfohlen: die GUID Ihres Tenants. Dann werden nur Anmeldungen aus diesem Tenant akzeptiert. „organizations“ erlaubt beliebige Geschäfts-, Schul- oder Unikonten."
|
||||
|
||||
#: includes/class-m365-login-admin.php:242
|
||||
msgid "Application (client) ID"
|
||||
msgstr "Anwendungs-ID (Client)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:247
|
||||
msgid "Client secret"
|
||||
msgstr "Geheimer Clientschlüssel (Client Secret)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "•••••••••••• (stored, leave empty to keep)"
|
||||
msgstr "•••••••••••• (gespeichert – leer lassen, um zu behalten)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "Paste the secret value"
|
||||
msgstr "Wert des Secrets einfügen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:250
|
||||
msgid "Show secret"
|
||||
msgstr "Secret anzeigen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:255
|
||||
msgid "Remove the stored secret"
|
||||
msgstr "Gespeichertes Secret entfernen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:258
|
||||
msgid "Stored encrypted (AES-256-GCM, key derived from your WordPress salts) and never displayed again. Client secrets expire – note the expiry date in Entra ID."
|
||||
msgstr "Wird verschlüsselt gespeichert (AES-256-GCM, Schlüssel aus den WordPress-Salts abgeleitet) und nie wieder angezeigt. Client Secrets laufen ab – Ablaufdatum in Entra ID notieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:262
|
||||
msgid "Account prompt"
|
||||
msgstr "Kontoauswahl"
|
||||
|
||||
#: includes/class-m365-login-admin.php:264
|
||||
msgid "Always let the user pick an account (recommended)"
|
||||
msgstr "Benutzer wählt immer ein Konto aus (empfohlen)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:265
|
||||
msgid "Use the current Microsoft session if available"
|
||||
msgstr "Vorhandene Microsoft-Sitzung verwenden, falls vorhanden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:266
|
||||
msgid "Always require re-entering credentials"
|
||||
msgstr "Immer erneute Eingabe der Anmeldedaten verlangen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:275
|
||||
msgid "Appearance"
|
||||
msgstr "Darstellung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:278
|
||||
msgid "Live preview"
|
||||
msgstr "Live-Vorschau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:292
|
||||
msgid "Button text"
|
||||
msgstr "Button-Text"
|
||||
|
||||
#: includes/class-m365-login-admin.php:296
|
||||
msgid "Divider text"
|
||||
msgstr "Trennlinien-Text"
|
||||
|
||||
#: includes/class-m365-login-admin.php:298
|
||||
msgid "Leave empty to hide the divider line."
|
||||
msgstr "Leer lassen, um die Trennlinie auszublenden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:303
|
||||
msgid "Icon"
|
||||
msgstr "Icon"
|
||||
|
||||
#: includes/class-m365-login-admin.php:306
|
||||
msgid "Show an icon on the button"
|
||||
msgstr "Icon auf dem Button anzeigen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:317
|
||||
msgid "Default: Microsoft logo"
|
||||
msgstr "Standard: Microsoft-Logo"
|
||||
|
||||
#: includes/class-m365-login-admin.php:319
|
||||
msgid "Choose from media library"
|
||||
msgstr "Aus Mediathek wählen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:320
|
||||
msgid "Use Microsoft logo"
|
||||
msgstr "Microsoft-Logo verwenden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:322
|
||||
msgid "PNG, SVG, JPG or WebP. Square images (e.g. 64×64 px) work best."
|
||||
msgstr "PNG, SVG, JPG oder WebP. Quadratische Bilder (z. B. 64×64 px) eignen sich am besten."
|
||||
|
||||
#: includes/class-m365-login-admin.php:330
|
||||
msgid "Background"
|
||||
msgstr "Hintergrund"
|
||||
|
||||
#: includes/class-m365-login-admin.php:331
|
||||
msgid "Background (hover)"
|
||||
msgstr "Hintergrund (Hover)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:332
|
||||
msgid "Text colour"
|
||||
msgstr "Textfarbe"
|
||||
|
||||
#: includes/class-m365-login-admin.php:333
|
||||
msgid "Border"
|
||||
msgstr "Rahmen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:346
|
||||
msgid "Corner radius"
|
||||
msgstr "Eckenradius"
|
||||
|
||||
#: includes/class-m365-login-admin.php:350
|
||||
msgid "Position on the login page"
|
||||
msgstr "Position auf der Login-Seite"
|
||||
|
||||
#: includes/class-m365-login-admin.php:352
|
||||
msgid "Below the login form"
|
||||
msgstr "Unter dem Login-Formular"
|
||||
|
||||
#: includes/class-m365-login-admin.php:353
|
||||
msgid "Above the login form"
|
||||
msgstr "Über dem Login-Formular"
|
||||
|
||||
#: includes/class-m365-login-admin.php:359
|
||||
msgid "Quick presets"
|
||||
msgstr "Schnellauswahl"
|
||||
|
||||
#: includes/class-m365-login-admin.php:360
|
||||
msgid "Microsoft dark"
|
||||
msgstr "Microsoft dunkel"
|
||||
|
||||
#: includes/class-m365-login-admin.php:361
|
||||
msgid "Microsoft light"
|
||||
msgstr "Microsoft hell"
|
||||
|
||||
#: includes/class-m365-login-admin.php:362
|
||||
msgid "Azure blue"
|
||||
msgstr "Azure-Blau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:363
|
||||
msgid "WordPress blue"
|
||||
msgstr "WordPress-Blau"
|
||||
|
||||
#: includes/class-m365-login-admin.php:371
|
||||
msgid "User matching & hardening"
|
||||
msgstr "Benutzerzuordnung & Härtung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:372
|
||||
msgid "Users are never created automatically. A Microsoft sign-in only succeeds when a WordPress user with the same e-mail address already exists."
|
||||
msgstr "Benutzer werden nie automatisch angelegt. Eine Microsoft-Anmeldung gelingt nur, wenn bereits ein WordPress-Benutzer mit derselben E-Mail-Adresse existiert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:377
|
||||
msgid "Bind WordPress accounts to the Microsoft object ID"
|
||||
msgstr "WordPress-Konten an die Microsoft-Objekt-ID binden"
|
||||
|
||||
#: includes/class-m365-login-admin.php:378
|
||||
msgid "On first sign-in the immutable Microsoft object ID is stored with the user. Later sign-ins with the same e-mail but a different Microsoft identity are rejected. Strongly recommended."
|
||||
msgstr "Bei der ersten Anmeldung wird die unveränderliche Microsoft-Objekt-ID am Benutzer gespeichert. Spätere Anmeldungen mit gleicher E-Mail, aber anderer Microsoft-Identität werden abgelehnt. Dringend empfohlen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:385
|
||||
msgid "Fall back to the user principal name (UPN)"
|
||||
msgstr "Auf den User Principal Name (UPN) zurückgreifen"
|
||||
|
||||
#: includes/class-m365-login-admin.php:386
|
||||
msgid "If the token contains no \"email\" claim, use the UPN (e.g. jane@contoso.com) when it is a valid e-mail address. Usually required for work accounts."
|
||||
msgstr "Enthält das Token keinen „email“-Claim, wird der UPN (z. B. jane@contoso.com) verwendet, sofern er eine gültige E-Mail-Adresse ist. Für Geschäftskonten meist erforderlich."
|
||||
|
||||
#: includes/class-m365-login-admin.php:393
|
||||
msgid "Keep users signed in (\"Remember me\")"
|
||||
msgstr "Benutzer angemeldet lassen („Angemeldet bleiben“)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:394
|
||||
msgid "Issues a 14-day WordPress session instead of a browser session."
|
||||
msgstr "Erstellt eine 14-tägige WordPress-Sitzung statt einer Browser-Sitzung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:399
|
||||
msgid "Allowed e-mail domains (optional)"
|
||||
msgstr "Erlaubte E-Mail-Domains (optional)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:401
|
||||
msgid "One or more domains separated by commas or new lines. Leave empty to allow any domain of your tenant."
|
||||
msgstr "Eine oder mehrere Domains, getrennt durch Kommas oder Zeilenumbrüche. Leer lassen, um alle Domains des Tenants zuzulassen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:406
|
||||
msgid "What the plugin does to keep sign-ins safe"
|
||||
msgstr "So schützt das Plugin die Anmeldung"
|
||||
|
||||
#: includes/class-m365-login-admin.php:408
|
||||
msgid "OpenID Connect authorization code flow with PKCE (S256) – no tokens ever pass through the browser."
|
||||
msgstr "OpenID Connect Authorization Code Flow mit PKCE (S256) – Tokens laufen nie durch den Browser."
|
||||
|
||||
#: includes/class-m365-login-admin.php:409
|
||||
msgid "Single-use state and nonce values bound to the browser via an HttpOnly cookie (CSRF and replay protection)."
|
||||
msgstr "Einmalige State- und Nonce-Werte, per HttpOnly-Cookie an den Browser gebunden (CSRF- und Replay-Schutz)."
|
||||
|
||||
#: includes/class-m365-login-admin.php:410
|
||||
msgid "ID token signature verified against Microsoft’s published signing keys; issuer, audience, tenant, expiry and nonce are checked."
|
||||
msgstr "Signatur des ID-Tokens wird gegen Microsofts veröffentlichte Signaturschlüssel geprüft; Issuer, Audience, Tenant, Ablauf und Nonce werden kontrolliert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:411
|
||||
msgid "Client secret encrypted at rest; no accounts are created, no passwords are changed."
|
||||
msgstr "Client Secret verschlüsselt gespeichert; es werden keine Konten angelegt und keine Passwörter geändert."
|
||||
|
||||
#: includes/class-m365-login-admin.php:417
|
||||
msgid "Save changes"
|
||||
msgstr "Änderungen speichern"
|
||||
|
||||
#: includes/class-m365-login-admin.php:423
|
||||
msgid "Redirect URI"
|
||||
msgstr "Umleitungs-URI (Redirect URI)"
|
||||
|
||||
#: includes/class-m365-login-admin.php:424
|
||||
msgid "Register this URI in your app registration under Authentication → Web → Redirect URIs:"
|
||||
msgstr "Diese URI in der App-Registrierung unter Authentifizierung → Web → Umleitungs-URIs eintragen:"
|
||||
|
||||
#: includes/class-m365-login-admin.php:430
|
||||
msgid "Plain permalinks are active, so the callback uses a query string. If you enable pretty permalinks later, the redirect URI changes and must be updated in Entra ID."
|
||||
msgstr "Einfache Permalinks sind aktiv, daher verwendet der Callback einen Query-String. Werden später sprechende Permalinks aktiviert, ändert sich die Umleitungs-URI und muss in Entra ID angepasst werden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:433
|
||||
msgid "Your site does not use HTTPS. Microsoft only accepts http:// redirect URIs for localhost; production sites must use HTTPS."
|
||||
msgstr "Diese Website nutzt kein HTTPS. Microsoft akzeptiert http://-Umleitungs-URIs nur für localhost; produktive Websites benötigen HTTPS."
|
||||
|
||||
#: includes/class-m365-login-admin.php:438
|
||||
msgid "Setup in 5 steps"
|
||||
msgstr "Einrichtung in 5 Schritten"
|
||||
|
||||
#: includes/class-m365-login-admin.php:440
|
||||
msgid "Open the Microsoft Entra admin center → App registrations → New registration."
|
||||
msgstr "Microsoft Entra Admin Center öffnen → App-Registrierungen → Neue Registrierung."
|
||||
|
||||
#: includes/class-m365-login-admin.php:441
|
||||
msgid "Choose \"Accounts in this organizational directory only\", set the platform to Web and paste the redirect URI above."
|
||||
msgstr "„Nur Konten in diesem Organisationsverzeichnis“ wählen, Plattform „Web“ auswählen und die Umleitungs-URI von oben einfügen."
|
||||
|
||||
#: includes/class-m365-login-admin.php:442
|
||||
msgid "Copy the Application (client) ID and Directory (tenant) ID from the overview page."
|
||||
msgstr "Anwendungs-ID (Client) und Verzeichnis-ID (Mandant) von der Übersichtsseite kopieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:443
|
||||
msgid "Under Certificates & secrets create a client secret and copy its value (not the ID)."
|
||||
msgstr "Unter „Zertifikate & Geheimnisse“ einen geheimen Clientschlüssel erstellen und dessen Wert (nicht die ID) kopieren."
|
||||
|
||||
#: includes/class-m365-login-admin.php:444
|
||||
msgid "Under Token configuration add the optional claim \"email\" for ID tokens (recommended), then save this page."
|
||||
msgstr "Unter „Tokenkonfiguration“ den optionalen Anspruch „email“ für ID-Tokens hinzufügen (empfohlen), dann diese Seite speichern."
|
||||
|
||||
#: includes/class-m365-login-admin.php:446
|
||||
msgid "Required API permission: openid, profile, email (delegated) – granted by default."
|
||||
msgstr "Benötigte API-Berechtigungen: openid, profile, email (delegiert) – standardmäßig vorhanden."
|
||||
|
||||
#: includes/class-m365-login-admin.php:450
|
||||
msgid "Shortcode"
|
||||
msgstr "Shortcode"
|
||||
|
||||
#: includes/class-m365-login-admin.php:451
|
||||
msgid "Place the button on a custom login page:"
|
||||
msgstr "Button auf einer eigenen Login-Seite platzieren:"
|
||||
|
||||
#: includes/class-m365-login-auth.php:593
|
||||
msgid "Microsoft login is not configured yet."
|
||||
msgstr "Die Microsoft-Anmeldung ist noch nicht eingerichtet."
|
||||
|
||||
#: includes/class-m365-login-auth.php:594
|
||||
msgid "The login request expired or was invalid. Please try again."
|
||||
msgstr "Die Anmeldeanfrage ist abgelaufen oder ungültig. Bitte erneut versuchen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:595
|
||||
msgid "Microsoft sign-in was cancelled."
|
||||
msgstr "Die Microsoft-Anmeldung wurde abgebrochen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:596
|
||||
msgid "Microsoft returned an error. Please try again."
|
||||
msgstr "Microsoft hat einen Fehler gemeldet. Bitte erneut versuchen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:597
|
||||
msgid "Could not complete the sign-in with Microsoft. Please try again or contact an administrator."
|
||||
msgstr "Die Anmeldung über Microsoft konnte nicht abgeschlossen werden. Bitte erneut versuchen oder einen Administrator kontaktieren."
|
||||
|
||||
#: includes/class-m365-login-auth.php:598
|
||||
msgid "The Microsoft sign-in could not be verified."
|
||||
msgstr "Die Microsoft-Anmeldung konnte nicht verifiziert werden."
|
||||
|
||||
#: includes/class-m365-login-auth.php:599
|
||||
msgid "Your Microsoft account did not provide an e-mail address."
|
||||
msgstr "Das Microsoft-Konto hat keine E-Mail-Adresse übermittelt."
|
||||
|
||||
#: includes/class-m365-login-auth.php:600
|
||||
msgid "Your e-mail domain is not allowed to sign in here."
|
||||
msgstr "Diese E-Mail-Domain ist hier nicht zur Anmeldung zugelassen."
|
||||
|
||||
#: includes/class-m365-login-auth.php:601
|
||||
msgid "No WordPress account exists for your Microsoft e-mail address."
|
||||
msgstr "Für die E-Mail-Adresse des Microsoft-Kontos existiert kein WordPress-Konto."
|
||||
|
||||
#: includes/class-m365-login-auth.php:602
|
||||
msgid "This WordPress account is linked to a different Microsoft account. Please contact an administrator."
|
||||
msgstr "Dieses WordPress-Konto ist mit einem anderen Microsoft-Konto verknüpft. Bitte einen Administrator kontaktieren."
|
||||
|
||||
#: includes/class-m365-login-auth.php:603
|
||||
msgid "You are not allowed to sign in with this account."
|
||||
msgstr "Die Anmeldung mit diesem Konto ist nicht erlaubt."
|
||||
|
||||
#: includes/class-m365-login-settings.php:40
|
||||
msgid "Sign in with Microsoft"
|
||||
msgstr "Login mit Microsoft"
|
||||
|
||||
#: includes/class-m365-login-settings.php:49
|
||||
msgid "or"
|
||||
msgstr "oder"
|
||||
|
||||
#: includes/class-m365-login-settings.php:176
|
||||
msgid "The tenant ID must be a GUID (e.g. 1a2b3c4d-…) or one of \"organizations\", \"common\", \"consumers\"."
|
||||
msgstr "Die Tenant-ID muss eine GUID (z. B. 1a2b3c4d-…) oder einer der Werte „organizations“, „common“, „consumers“ sein."
|
||||
|
||||
#: includes/class-m365-login-settings.php:184
|
||||
msgid "The application (client) ID must be a GUID."
|
||||
msgstr "Die Anwendungs-ID (Client) muss eine GUID sein."
|
||||
|
||||
#: includes/class-m365-login-settings.php:196
|
||||
msgid "The client secret contains invalid characters."
|
||||
msgstr "Das Client Secret enthält ungültige Zeichen."
|
||||
|
||||
#: includes/class-m365-login-settings.php:200
|
||||
msgid "The client secret could not be encrypted. Is the OpenSSL extension available?"
|
||||
msgstr "Das Client Secret konnte nicht verschlüsselt werden. Ist die OpenSSL-Erweiterung verfügbar?"
|
||||
|
||||
#: includes/class-m365-login.php:94
|
||||
msgid "Settings"
|
||||
msgstr "Einstellungen"
|
||||
|
||||
#: includes/class-m365-login.php:105
|
||||
msgid "M365 Login requires PHP 7.4 or newer."
|
||||
msgstr "M365 Login benötigt PHP 7.4 oder neuer."
|
||||
|
||||
#: includes/class-m365-login.php:106 includes/class-m365-login.php:115
|
||||
msgid "Plugin activation failed"
|
||||
msgstr "Plugin-Aktivierung fehlgeschlagen"
|
||||
|
||||
#: includes/class-m365-login.php:114
|
||||
msgid "M365 Login requires the PHP OpenSSL extension (needed to verify Microsoft token signatures and to encrypt the client secret)."
|
||||
msgstr "M365 Login benötigt die PHP-Erweiterung OpenSSL (zur Prüfung der Microsoft-Token-Signaturen und zur Verschlüsselung des Client Secrets)."
|
||||
|
||||
458
languages/m365-login.pot
Normal file
458
languages/m365-login.pot
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
# Copyright (C) 2026 friloo
|
||||
# This file is distributed under the GPL-2.0-or-later.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: M365 Login 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/friloo/wp-m365-login/issues\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-09-22T00:00:00+00:00\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"X-Generator: bin/make-pot.py\n"
|
||||
"X-Domain: m365-login\n"
|
||||
|
||||
#: includes/class-m365-login-admin.php:63 includes/class-m365-login-admin.php:64 includes/class-m365-login-admin.php:203
|
||||
msgid "M365 Login"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:102
|
||||
msgid "M365 Login is active but not connected to Microsoft Entra ID yet."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:104
|
||||
msgid "Open the settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:132
|
||||
msgid "Choose button icon"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:133
|
||||
msgid "Use this icon"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:134
|
||||
msgid "Copied!"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:135 includes/class-m365-login-admin.php:427
|
||||
msgid "Copy"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:136
|
||||
msgid "Testing…"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:137
|
||||
msgid "The tenant could not be reached. Check the tenant ID and the server’s outgoing connections."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:149
|
||||
msgid "You are not allowed to do this."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:154
|
||||
msgid "Please enter a valid tenant ID first."
|
||||
msgstr ""
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:168
|
||||
msgid "Microsoft answered with HTTP %d. Is the tenant ID correct?"
|
||||
msgstr ""
|
||||
|
||||
#. translators: %d: HTTP status code
|
||||
#: includes/class-m365-login-admin.php:177
|
||||
msgid "Tenant reachable. The OpenID configuration was loaded successfully."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:187
|
||||
msgid "You are not allowed to access this page."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:204
|
||||
msgid "Let existing users sign in with their Microsoft 365 / Entra ID account."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Connected"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:209
|
||||
msgid "Setup incomplete"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:217
|
||||
msgid "Connection"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:218
|
||||
msgid "Button"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:219
|
||||
msgid "Security"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:228
|
||||
msgid "Microsoft Entra ID app registration"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:229
|
||||
msgid "Enter the values from your app registration in the Microsoft Entra admin center."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:232
|
||||
msgid "Directory (tenant) ID"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:235
|
||||
msgid "Test tenant"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:237
|
||||
msgid "Recommended: the GUID of your tenant. Only sign-ins from this tenant are accepted. \"organizations\" allows any work or school account."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:242
|
||||
msgid "Application (client) ID"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:247
|
||||
msgid "Client secret"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "•••••••••••• (stored, leave empty to keep)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:249
|
||||
msgid "Paste the secret value"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:250
|
||||
msgid "Show secret"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:255
|
||||
msgid "Remove the stored secret"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:258
|
||||
msgid "Stored encrypted (AES-256-GCM, key derived from your WordPress salts) and never displayed again. Client secrets expire – note the expiry date in Entra ID."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:262
|
||||
msgid "Account prompt"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:264
|
||||
msgid "Always let the user pick an account (recommended)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:265
|
||||
msgid "Use the current Microsoft session if available"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:266
|
||||
msgid "Always require re-entering credentials"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:275
|
||||
msgid "Appearance"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:278
|
||||
msgid "Live preview"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:292
|
||||
msgid "Button text"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:296
|
||||
msgid "Divider text"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:298
|
||||
msgid "Leave empty to hide the divider line."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:303
|
||||
msgid "Icon"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:306
|
||||
msgid "Show an icon on the button"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:317
|
||||
msgid "Default: Microsoft logo"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:319
|
||||
msgid "Choose from media library"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:320
|
||||
msgid "Use Microsoft logo"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:322
|
||||
msgid "PNG, SVG, JPG or WebP. Square images (e.g. 64×64 px) work best."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:330
|
||||
msgid "Background"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:331
|
||||
msgid "Background (hover)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:332
|
||||
msgid "Text colour"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:333
|
||||
msgid "Border"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:346
|
||||
msgid "Corner radius"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:350
|
||||
msgid "Position on the login page"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:352
|
||||
msgid "Below the login form"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:353
|
||||
msgid "Above the login form"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:359
|
||||
msgid "Quick presets"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:360
|
||||
msgid "Microsoft dark"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:361
|
||||
msgid "Microsoft light"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:362
|
||||
msgid "Azure blue"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:363
|
||||
msgid "WordPress blue"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:371
|
||||
msgid "User matching & hardening"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:372
|
||||
msgid "Users are never created automatically. A Microsoft sign-in only succeeds when a WordPress user with the same e-mail address already exists."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:377
|
||||
msgid "Bind WordPress accounts to the Microsoft object ID"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:378
|
||||
msgid "On first sign-in the immutable Microsoft object ID is stored with the user. Later sign-ins with the same e-mail but a different Microsoft identity are rejected. Strongly recommended."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:385
|
||||
msgid "Fall back to the user principal name (UPN)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:386
|
||||
msgid "If the token contains no \"email\" claim, use the UPN (e.g. jane@contoso.com) when it is a valid e-mail address. Usually required for work accounts."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:393
|
||||
msgid "Keep users signed in (\"Remember me\")"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:394
|
||||
msgid "Issues a 14-day WordPress session instead of a browser session."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:399
|
||||
msgid "Allowed e-mail domains (optional)"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:401
|
||||
msgid "One or more domains separated by commas or new lines. Leave empty to allow any domain of your tenant."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:406
|
||||
msgid "What the plugin does to keep sign-ins safe"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:408
|
||||
msgid "OpenID Connect authorization code flow with PKCE (S256) – no tokens ever pass through the browser."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:409
|
||||
msgid "Single-use state and nonce values bound to the browser via an HttpOnly cookie (CSRF and replay protection)."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:410
|
||||
msgid "ID token signature verified against Microsoft’s published signing keys; issuer, audience, tenant, expiry and nonce are checked."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:411
|
||||
msgid "Client secret encrypted at rest; no accounts are created, no passwords are changed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:417
|
||||
msgid "Save changes"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:423
|
||||
msgid "Redirect URI"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:424
|
||||
msgid "Register this URI in your app registration under Authentication → Web → Redirect URIs:"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:430
|
||||
msgid "Plain permalinks are active, so the callback uses a query string. If you enable pretty permalinks later, the redirect URI changes and must be updated in Entra ID."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:433
|
||||
msgid "Your site does not use HTTPS. Microsoft only accepts http:// redirect URIs for localhost; production sites must use HTTPS."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:438
|
||||
msgid "Setup in 5 steps"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:440
|
||||
msgid "Open the Microsoft Entra admin center → App registrations → New registration."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:441
|
||||
msgid "Choose \"Accounts in this organizational directory only\", set the platform to Web and paste the redirect URI above."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:442
|
||||
msgid "Copy the Application (client) ID and Directory (tenant) ID from the overview page."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:443
|
||||
msgid "Under Certificates & secrets create a client secret and copy its value (not the ID)."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:444
|
||||
msgid "Under Token configuration add the optional claim \"email\" for ID tokens (recommended), then save this page."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:446
|
||||
msgid "Required API permission: openid, profile, email (delegated) – granted by default."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:450
|
||||
msgid "Shortcode"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-admin.php:451
|
||||
msgid "Place the button on a custom login page:"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:593
|
||||
msgid "Microsoft login is not configured yet."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:594
|
||||
msgid "The login request expired or was invalid. Please try again."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:595
|
||||
msgid "Microsoft sign-in was cancelled."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:596
|
||||
msgid "Microsoft returned an error. Please try again."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:597
|
||||
msgid "Could not complete the sign-in with Microsoft. Please try again or contact an administrator."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:598
|
||||
msgid "The Microsoft sign-in could not be verified."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:599
|
||||
msgid "Your Microsoft account did not provide an e-mail address."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:600
|
||||
msgid "Your e-mail domain is not allowed to sign in here."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:601
|
||||
msgid "No WordPress account exists for your Microsoft e-mail address."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:602
|
||||
msgid "This WordPress account is linked to a different Microsoft account. Please contact an administrator."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-auth.php:603
|
||||
msgid "You are not allowed to sign in with this account."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:40
|
||||
msgid "Sign in with Microsoft"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:49
|
||||
msgid "or"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:176
|
||||
msgid "The tenant ID must be a GUID (e.g. 1a2b3c4d-…) or one of \"organizations\", \"common\", \"consumers\"."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:184
|
||||
msgid "The application (client) ID must be a GUID."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:196
|
||||
msgid "The client secret contains invalid characters."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login-settings.php:200
|
||||
msgid "The client secret could not be encrypted. Is the OpenSSL extension available?"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login.php:94
|
||||
msgid "Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login.php:105
|
||||
msgid "M365 Login requires PHP 7.4 or newer."
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login.php:106 includes/class-m365-login.php:115
|
||||
msgid "Plugin activation failed"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-m365-login.php:114
|
||||
msgid "M365 Login requires the PHP OpenSSL extension (needed to verify Microsoft token signatures and to encrypt the client secret)."
|
||||
msgstr ""
|
||||
|
||||
35
m365-login.php
Normal file
35
m365-login.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: M365 Login
|
||||
* Plugin URI: https://github.com/friloo/wp-m365-login
|
||||
* Description: Adds a customisable "Sign in with Microsoft" button to the WordPress login page. Existing users are matched by e-mail address via Microsoft Entra ID (OpenID Connect, PKCE).
|
||||
* Version: 1.0.0
|
||||
* Requires at least: 6.0
|
||||
* Requires PHP: 7.4
|
||||
* Author: friloo
|
||||
* Author URI: https://github.com/friloo
|
||||
* License: GPL-2.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* Text Domain: m365-login
|
||||
* Domain Path: /languages
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
define( 'M365_LOGIN_VERSION', '1.0.0' );
|
||||
define( 'M365_LOGIN_FILE', __FILE__ );
|
||||
define( 'M365_LOGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||
define( 'M365_LOGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
define( 'M365_LOGIN_OPTION', 'm365_login_settings' );
|
||||
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-settings.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-crypto.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-jwt.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-auth.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-button.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login-admin.php';
|
||||
require_once M365_LOGIN_DIR . 'includes/class-m365-login.php';
|
||||
|
||||
register_activation_hook( __FILE__, array( 'M365_Login', 'activate' ) );
|
||||
|
||||
add_action( 'plugins_loaded', array( 'M365_Login', 'instance' ) );
|
||||
43
phpcs.xml.dist
Normal file
43
phpcs.xml.dist
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="M365 Login">
|
||||
<description>WordPress Coding Standards for the M365 Login plugin.</description>
|
||||
|
||||
<file>.</file>
|
||||
<exclude-pattern>/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>/build/*</exclude-pattern>
|
||||
<exclude-pattern>/bin/*</exclude-pattern>
|
||||
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="colors"/>
|
||||
<arg value="sp"/>
|
||||
<arg name="parallel" value="8"/>
|
||||
|
||||
<rule ref="WordPress">
|
||||
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
|
||||
</rule>
|
||||
<rule ref="WordPress-Extra"/>
|
||||
<rule ref="WordPress-Docs"/>
|
||||
|
||||
<config name="minimum_wp_version" value="6.0"/>
|
||||
<config name="testVersion" value="7.4-"/>
|
||||
<rule ref="PHPCompatibilityWP"/>
|
||||
|
||||
<rule ref="WordPress.WP.I18n">
|
||||
<properties>
|
||||
<property name="text_domain" type="array">
|
||||
<element value="m365-login"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
|
||||
<properties>
|
||||
<property name="prefixes" type="array">
|
||||
<element value="m365_login"/>
|
||||
<element value="M365_LOGIN"/>
|
||||
<element value="M365_Login"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
||||
116
readme.txt
Normal file
116
readme.txt
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
=== M365 Login ===
|
||||
Contributors: friloo
|
||||
Tags: microsoft, entra id, azure ad, sso, login
|
||||
Requires at least: 6.0
|
||||
Tested up to: 6.9
|
||||
Requires PHP: 7.4
|
||||
Stable tag: 1.0.0
|
||||
License: GPLv2 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Adds a customisable "Sign in with Microsoft" button to the login page. Existing users sign in with their Microsoft 365 / Entra ID account, matched by e-mail address.
|
||||
|
||||
== Description ==
|
||||
|
||||
**M365 Login** lets your existing WordPress users sign in with their Microsoft 365 (Microsoft Entra ID, formerly Azure AD) work or school account. It adds a button to the standard WordPress login screen and uses the OpenID Connect authorization code flow with PKCE.
|
||||
|
||||
The plugin is deliberately small and strict:
|
||||
|
||||
* **No user provisioning.** A Microsoft sign-in succeeds only when a WordPress user with the same e-mail address already exists. Nobody gets an account just by having a Microsoft login.
|
||||
* **Password login stays available.** The button is an additional option; the normal form is untouched.
|
||||
* **Fully customisable button.** Change the text, replace the Microsoft logo with your own icon from the media library, pick background, hover, text and border colours, adjust the corner radius, and choose whether the button appears above or below the login form – with a live preview.
|
||||
* **Clean settings screen** with a copy-and-paste redirect URI, a tenant connectivity test and a five-step setup guide.
|
||||
* **Shortcode** `[m365_login_button]` for custom login pages.
|
||||
|
||||
= Security =
|
||||
|
||||
* OpenID Connect **authorization code flow with PKCE (S256)** – tokens are exchanged server-to-server and never pass through the browser.
|
||||
* **Single-use state and nonce** values, bound to the browser with an HttpOnly, SameSite cookie (CSRF and replay protection).
|
||||
* The **ID token signature is verified** against Microsoft's published signing keys (JWKS, cached and refreshed on key rollover). Issuer, audience, tenant, expiry, not-before and nonce are all checked. Only RS256 is accepted.
|
||||
* Optional **tenant pinning**: when a tenant GUID is configured, tokens from any other tenant are rejected.
|
||||
* **Account binding**: on first sign-in the immutable Microsoft object ID is stored with the user; later sign-ins with the same e-mail but a different Microsoft identity are refused.
|
||||
* Optional **e-mail domain allow-list**.
|
||||
* The **client secret is encrypted at rest** (AES-256-GCM, key derived from your WordPress salts) and never displayed again.
|
||||
* Every setting is sanitised, every output escaped, every admin request nonce- and capability-checked.
|
||||
|
||||
= Developer hooks =
|
||||
|
||||
* `m365_login_show_button` – filter, hide the button conditionally.
|
||||
* `m365_login_authorize_params` – filter the parameters sent to Microsoft (e.g. `domain_hint`).
|
||||
* `m365_login_match_email` – filter the e-mail address used for the lookup.
|
||||
* `m365_login_allow_user` – filter, return `false` to block a matched user (e.g. group checks).
|
||||
* `m365_login_success` – action after a successful sign-in, receives the user and verified claims.
|
||||
|
||||
== External services ==
|
||||
|
||||
This plugin connects to **Microsoft identity platform (Microsoft Entra ID)** to authenticate users. It is required for the plugin's only purpose – signing users in with their Microsoft account – and is only contacted when a user clicks the Microsoft button or when an administrator uses the "Test tenant" button.
|
||||
|
||||
Endpoints used (all under `https://login.microsoftonline.com/`):
|
||||
|
||||
* `/{tenant}/oauth2/v2.0/authorize` – the user's browser is redirected here to sign in at Microsoft. Microsoft receives the application (client) ID, the redirect URI of this site, a random state, nonce and PKCE challenge.
|
||||
* `/{tenant}/oauth2/v2.0/token` – the server exchanges the authorization code for an ID token. Microsoft receives the client ID, client secret, the code and the PKCE verifier.
|
||||
* `/{tenant}/discovery/v2.0/keys` – the server downloads Microsoft's public signing keys to verify the ID token. No user data is sent.
|
||||
* `/{tenant}/v2.0/.well-known/openid-configuration` – fetched only when an administrator clicks "Test tenant". No user data is sent.
|
||||
|
||||
The plugin receives the user's e-mail address / user principal name, display name and Microsoft object ID from Microsoft and uses them solely to find the matching WordPress account. Nothing else is stored.
|
||||
|
||||
Microsoft terms and privacy: [Microsoft Services Agreement](https://www.microsoft.com/servicesagreement), [Microsoft Privacy Statement](https://privacy.microsoft.com/privacystatement), [Microsoft identity platform documentation](https://learn.microsoft.com/entra/identity-platform/).
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Upload the plugin folder to `/wp-content/plugins/` or install it through the WordPress plugin screen, then activate it.
|
||||
2. Go to **Settings → M365 Login** and copy the **Redirect URI** shown in the sidebar.
|
||||
3. In the [Microsoft Entra admin center](https://entra.microsoft.com/) open **App registrations → New registration**. Choose *Accounts in this organizational directory only*, select the **Web** platform and paste the redirect URI.
|
||||
4. From the app's overview page copy the **Application (client) ID** and the **Directory (tenant) ID** into the plugin settings.
|
||||
5. Under **Certificates & secrets** create a client secret and paste its *value* into the plugin settings.
|
||||
6. Under **Token configuration** add the optional claim **email** for ID tokens (recommended). The delegated permissions `openid`, `profile` and `email` are granted by default.
|
||||
7. Save. The button now appears on `wp-login.php`. Customise it on the **Button** tab.
|
||||
|
||||
Make sure every user who should be able to sign in has the same e-mail address in WordPress as in Microsoft 365.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Does the plugin create users? =
|
||||
|
||||
No. Users must already exist in WordPress. The e-mail address is the only link between the Microsoft account and the WordPress account. This is intentional – it keeps the administrator in control of who can access the site.
|
||||
|
||||
= Which accounts can sign in? =
|
||||
|
||||
Any Microsoft account of the configured tenant whose e-mail address (or user principal name) matches an existing WordPress user. Restrict it further with the e-mail domain allow-list or the `m365_login_allow_user` filter.
|
||||
|
||||
= Can I use it with personal Microsoft accounts (outlook.com)? =
|
||||
|
||||
Set the tenant to `consumers` or `common`. Note that Microsoft does not allow query strings in redirect URIs for apps that support personal accounts, so your site must use pretty permalinks (the callback URL is then `/m365-login/callback` without a query string).
|
||||
|
||||
= The sign-in fails with "No WordPress account exists for your Microsoft e-mail address" =
|
||||
|
||||
The e-mail address in the Microsoft token does not match any WordPress user. Check the user's e-mail address in WordPress, enable the UPN fallback on the Security tab, or add the `email` optional claim in the app registration.
|
||||
|
||||
= Does it work with custom login pages? =
|
||||
|
||||
Yes, use the shortcode `[m365_login_button redirect="/dashboard/"]`.
|
||||
|
||||
= Does it support multisite? =
|
||||
|
||||
Yes. Settings are per site; a user must be a member of the site (or a super admin) to sign in.
|
||||
|
||||
= What happens on uninstall? =
|
||||
|
||||
The settings, cached data and the per-user Microsoft object ID are removed.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. The customised button on the WordPress login screen.
|
||||
2. Settings – Connection tab with redirect URI and tenant test.
|
||||
3. Settings – Button tab with live preview, colour pickers and icon picker.
|
||||
4. Settings – Security tab.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.0.0 =
|
||||
* Initial release.
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.0.0 =
|
||||
Initial release.
|
||||
45
uninstall.php
Normal file
45
uninstall.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Removes all plugin data on uninstall.
|
||||
*
|
||||
* @package M365_Login
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
/**
|
||||
* Deletes options, transients and user meta for one site.
|
||||
*/
|
||||
function m365_login_uninstall_site() {
|
||||
global $wpdb;
|
||||
|
||||
delete_option( 'm365_login_settings' );
|
||||
|
||||
// Transients: state records and JWKS cache.
|
||||
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
|
||||
$wpdb->esc_like( '_transient_m365_login_' ) . '%',
|
||||
$wpdb->esc_like( '_transient_timeout_m365_login_' ) . '%'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$m365_login_site_ids = get_sites( array( 'fields' => 'ids', 'number' => 0 ) );
|
||||
foreach ( $m365_login_site_ids as $m365_login_site_id ) {
|
||||
switch_to_blog( $m365_login_site_id );
|
||||
m365_login_uninstall_site();
|
||||
restore_current_blog();
|
||||
}
|
||||
} else {
|
||||
m365_login_uninstall_site();
|
||||
}
|
||||
|
||||
// User meta is global.
|
||||
delete_metadata( 'user', 0, '_m365_login_oid', '', true );
|
||||
delete_metadata( 'user', 0, '_m365_login_last_login', '', true );
|
||||
Loading…
Add table
Add a link
Reference in a new issue