私は 'spring-cloud-oauth2'と 'spring-cloud-security'で保護されたoauth-serverを持っています。アプリケーションはスプリングブートアプリケーションです。私は角度2アプリからaccess_tokenを取得しようとしています。つまり、角度2アプリからログインしたいと思っています。私のoauth-serverでは、私はclient-id = microserviceとclient-secret = microservicesecretを持っています。 私はpostmanからoauth-serverを確認しました。ここで、認証セクションで、ユーザー名とパスワードはそれぞれclient-idとclient-secretを使用しています。 bodyセクションでは、grant_type = password、client_id = microservice、[email protected]、password = passw0rdを使用しています。ang 2アプリケーションをspring-oauth2サーバーに接続する方法は?
しかし、角度2アプリの設定を使用するのに問題があります。私は次のコードスニペットを使用しました。
userLogin(){
console.log("In the userLogin()");
var username:string='microservice';
var password:string='microservicesecret';
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('grant_type','password');
headers.append('client_id','microservice');
headers.append('client_secret','microservicesecret');
headers.append('username',this.user.userEmail);
headers.append('password',this.userPassword);
console.log("User");
console.log(this.user);
console.log(headers);
console.log(JSON.stringify({username:username,password:password}));
var data = "username=" + username + "&password=" + password ;
this.http
.post(this.loginUrl,
JSON.stringify({user,password}),
{headers}
)
.map(res=>res.json())
.map((res)=>{
if(res.success){
console.log("Success");
localStorage.setItem('access_token',res.access_token);
console.log("Access token");
console.log(res.access_token);
}
});
}
ここで、userEmailとuserPasswordがユーザーによって挿入されます。 トークンURLは
loginUrl:string="http://localhost:9000/services/oauth/token";
である。しかし、私は401エラーをgettngています。私は解決策が必要です。