Resolve Spring Security OAuth when visiting/oauth/token 401 authentication is required

Source: Internet
Author: User
Tags oauth

The specific cause of this problem is generally the following two points:

1. In the authorized section we generally authorize by using our own login action HTTP BASIC, while we use spring security only exposed the login interface, which means that the other interfaces are in spring Security protection, including the/oauth interface.

2. Use/oauth/authorize?grant_type=password&username=user&password=pwd&client_id=app after authorization via 1 post mode &response_type=code&redirect_uri=http://localhost way to authorize, this is possible, but in the next post way to/oauth/ Token this interface to get Access_token, will find this time authentication use is not the previous authorization of the authentication, but the use of the anonymous landing of the authentication, So the front of the authentication can not be used normally, it will be 401 authentication is required.


We can solve this problem in the following way, in Authenticationserverconfig this configuration, Enabling Authenticationserversecurityconfiguration Allowformauthenticationforclients allows the client to authorize authentication by using form , you can refer to the following code:

@Override public
void Configure (Authorizationserversecurityconfigurer oauthserver) throws Exception {
    // Enable client to get the authenticated if using The/oauth/token to get a access token
    //there is a 401 Authenticati On are required if it doesn ' t allow form authentication for clients when Access/oauth/token
    oauthserver.allowformauthe Nticationforclients ();
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.