Make WordPress Core

Changeset 49109

Timestamp:
10/08/2020 10:12:02 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Introduce Application Passwords for API authentication.

In WordPress 4.4 the REST API was first introduced. A few releases later in WordPress 4.7, the Content API endpoints were added, paving the way for Gutenberg and countless in-site experiences. In the intervening years, numerous plugins have built on top of the REST API. Many developers shared a common frustration, the lack of external authentication to the REST API.

This commit introduces Application Passwords to allow users to connect to external applications to their WordPress website. Users can generate individual passwords for each application, allowing for easy revocation and activity monitoring. An authorization flow is introduced to make the connection flow simple for users and application developers.

Application Passwords uses Basic Authentication, and by default is only available over an SSL connection.

Props georgestephanis, kasparsd, timothyblynjacobs, afercia, akkspro, andraganescu, arippberger, aristath, austyfrosty, ayesh, batmoo, bradyvercher, brianhenryie, helen, ipstenu, jeffmatson, jeffpaul, joostdevalk, joshlevinson, kadamwhite, kjbenk, koke, michael-arestad, Otto42, pekz0r, salzano, spacedmonkey, valendesigns.
Fixes #42790.

Location:
trunk
Files:
8 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r49101 r49109  
    239239                files: {
    240240                    [ WORKING_DIR + 'wp-admin/js/accordion.js' ]: [ './src/js/_enqueues/lib/accordion.js' ],
     241
     242
    241243                    [ WORKING_DIR + 'wp-admin/js/code-editor.js' ]: [ './src/js/_enqueues/wp/code-editor.js' ],
    242244                    [ WORKING_DIR + 'wp-admin/js/color-picker.js' ]: [ './src/js/_enqueues/lib/color-picker.js' ],
     
    797799                file_mappings: {
    798800                    'src/wp-admin/js/accordion.js': 'src/js/_enqueues/lib/accordion.js',
     801
     802
    799803                    'src/wp-admin/js/code-editor.js': 'src/js/_enqueues/wp/code-editor.js',
    800804                    'src/wp-admin/js/color-picker.js': 'src/js/_enqueues/lib/color-picker.js',
  • trunk/src/wp-admin/css/forms.css

    r48419 r49109  
    757757}
    758758
    759 .form-table td fieldset p label { 
     759.form-table td fieldset p label {
    760760    margin-top: 0 !important;
    761761}
     
    840840.color-option {
    841841    cursor: pointer;
     842
     843
     844
     845
     846
    842847}
    843848
  • trunk/src/wp-admin/includes/list-table.php

    r48574 r49109  
    3434        'WP_Theme_Install_List_Table'                 => array( 'themes', 'theme-install' ),
    3535        'WP_Plugins_List_Table'                       => 'plugins',
     36
    3637
    3738        // Network Admin.
  • trunk/src/wp-admin/includes/user.php

    r48313 r49109  
    595595    );
    596596}
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
  • trunk/src/wp-admin/user-edit.php

    r47808 r49109  
    2727
    2828wp_enqueue_script( 'user-profile' );
     29
     30
     31
     32
    2933
    3034if ( IS_PROFILE_PAGE ) {
     
    703707    </table>
    704708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
    705742        <?php
    706743        if ( IS_PROFILE_PAGE ) {
     
    788825    }
    789826</script>
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
    790852<?php
    791853require_once ABSPATH . 'wp-admin/admin-footer.php';
  • trunk/src/wp-includes/class-wp-rewrite.php

    r48585 r49109  
    15101510        $rules  = "<IfModule mod_rewrite.c>\n";
    15111511        $rules .= "RewriteEngine On\n";
     1512
    15121513        $rules .= "RewriteBase $home_root\n";
    15131514
  • trunk/src/wp-includes/default-filters.php

    r48966 r49109  
    277277add_action( 'auth_cookie_bad_hash', 'rest_cookie_collect_status' );
    278278add_action( 'auth_cookie_valid', 'rest_cookie_collect_status' );
     279
     280
     281
    279282add_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
    280283
     
    428431add_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
    429432add_filter( 'authenticate', 'wp_authenticate_email_password', 20, 3 );
     433
    430434add_filter( 'authenticate', 'wp_authenticate_spam_check', 99 );
    431435add_filter( 'determine_current_user', 'wp_validate_auth_cookie' );
    432436add_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 );
     437
    433438
    434439// Split term updates.
  • trunk/src/wp-includes/load.php

    r49023 r49109  
    8787        $PHP_SELF            = $_SERVER['PHP_SELF'];
    8888    }
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
    89130}
    90131
  • trunk/src/wp-includes/rest-api.php

    r49108 r49109  
    210210
    211211    add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );
     212
    212213}
    213214
     
    263264    // Users.
    264265    $controller = new WP_REST_Users_Controller;
     266
     267
     268
     269
    265270    $controller->register_routes();
    266271
     
    311316    $controller = new WP_REST_Block_Directory_Controller();
    312317    $controller->register_routes();
    313 
    314318}
    315319
     
    10331037
    10341038    $wp_rest_auth_cookie = true;
     1039
     1040
     1041
     1042
     1043
     1044
     1045
     1046
     1047
     1048
     1049
     1050
     1051
     1052
     1053
     1054
     1055
     1056
     1057
     1058
     1059
     1060
     1061
     1062
     1063
     1064
     1065
     1066
     1067
     1068
     1069
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
    10351113}
    10361114
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r49075 r49109  
    224224     * @see WP_REST_Server::dispatch()
    225225     *
     226
     227
    226228     * @param string $path Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used.
    227229     *                     Default null.
     
    229231     */
    230232    public function serve_request( $path = null ) {
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
    231250        $content_type = isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json';
    232251        $this->send_header( 'Content-Type', $content_type . '; charset=' . get_option( 'blog_charset' ) );
  • trunk/src/wp-includes/script-loader.php

    r49104 r49109  
    10681068    $scripts->set_translations( 'password-strength-meter' );
    10691069
     1070
     1071
     1072
     1073
     1074
     1075
    10701076    $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
    10711077    $scripts->set_translations( 'user-profile' );
  • trunk/src/wp-includes/user.php

    r49090 r49109  
    296296
    297297    return $user;
     298
     299
     300
     301
     302
     303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
    298468}
    299469
     
    39244094    return new WP_User_Request( $post );
    39254095}
     4096
     4097
     4098
     4099
     4100
     4101
     4102
     4103
     4104
     4105
     4106
     4107
     4108
     4109
     4110
     4111
     4112
     4113
     4114
     4115
     4116
     4117
     4118
     4119
     4120
     4121
     4122
     4123
     4124
     4125
     4126
     4127
     4128
     4129
     4130
     4131
     4132
     4133
     4134
     4135
     4136
     4137
     4138
     4139
     4140
     4141
     4142
     4143
     4144
     4145
     4146
     4147
     4148
     4149
     4150
     4151
  • trunk/src/wp-login.php

    r49078 r49109  
    13721372            } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
    13731373                $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
     1374
     1375
     1376
     1377
     1378
     1379
     1380
     1381
     1382
     1383
     1384
     1385
     1386
    13741387            }
    13751388        }
  • trunk/src/wp-settings.php

    r49103 r49109  
    237237require ABSPATH . WPINC . '/nav-menu-template.php';
    238238require ABSPATH . WPINC . '/admin-bar.php';
     239
    239240require ABSPATH . WPINC . '/rest-api.php';
    240241require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php';
     
    260261require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-plugins-controller.php';
    261262require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-directory-controller.php';
     263
    262264require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php';
    263265require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php';
  • trunk/tests/phpunit/tests/auth.php

    r48937 r49109  
    77class Tests_Auth extends WP_UnitTestCase {
    88    protected $user;
     9
     10
     11
     12
    913    protected static $_user;
    1014    protected static $user_id;
     
    3438        $this->user = clone self::$_user;
    3539        wp_set_current_user( self::$user_id );
     40
     41
     42
     43
     44
     45
     46
    3647    }
    3748
     
    415426    }
    416427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
    417607}
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r48937 r49109  
    119119            '/wp/v2/users/(?P<id>[\\d]+)',
    120120            '/wp/v2/users/me',
     121
     122
    121123            '/wp/v2/comments',
    122124            '/wp/v2/comments/(?P<id>[\\d]+)',
     
    133135        );
    134136
    135         $this->assertSame( $expected_routes, $routes );
     137        $this->assertSame( $expected_routes, $routes );
    136138    }
    137139
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r49103 r49109  
    39853985                "self": "http://example.org/index.php?rest_route=/wp/v2/users/me"
    39863986            }
     3987
     3988
     3989
     3990
     3991
     3992
     3993
     3994
     3995
     3996
     3997
     3998
     3999
     4000
     4001
     4002
     4003
     4004
     4005
     4006
     4007
     4008
     4009
     4010
     4011
     4012
     4013
     4014
     4015
     4016
     4017
     4018
     4019
     4020
     4021
     4022
     4023
     4024
     4025
     4026
     4027
     4028
     4029
     4030
     4031
     4032
     4033
     4034
     4035
     4036
     4037
     4038
     4039
     4040
     4041
     4042
     4043
     4044
     4045
     4046
     4047
     4048
     4049
     4050
     4051
     4052
     4053
     4054
     4055
     4056
     4057
     4058
     4059
     4060
     4061
     4062
     4063
     4064
     4065
     4066
     4067
     4068
     4069
     4070
     4071
     4072
     4073
     4074
     4075
     4076
     4077
     4078
     4079
     4080
     4081
     4082
    39874083        },
    39884084        "/wp/v2/comments": {
Note: See TracChangeset for help on using the changeset viewer.