Flutter OAuth2 с пользовательским бэкэндом Spring BootAndroid

Форум для тех, кто программирует под Android
Anonymous
Flutter OAuth2 с пользовательским бэкэндом Spring Boot

Сообщение Anonymous »

Я хочу подключить свое приложение Flutter к серверной части Spring Boot, чтобы пользователь мог войти в систему через OAuth2.
Конфигурация Spring Security:

Код: Выделить всё

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import shoppinglist.service.configurations.security.oauth2userService.CustomOAuth2UserService;
import shoppinglist.service.configurations.security.oauth2userService.CustomOidcUserService;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled=true)
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private final CustomOidcUserService customOidcUserService;
@Autowired
private final CustomOAuth2UserService customOAuth2UserService;

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.cors().disable()
.authorizeRequests()
.antMatchers("/**").permitAll()
.and()
.oauth2Login()
.userInfoEndpoint().oidcUserService(customOidcUserService).userService(customOAuth2UserService)
.and().defaultSuccessUrl("/", true)
.and()
)
.logout(l -> l
.logoutSuccessUrl("/").permitAll()
);
}
}

Вызов «http://localhost:8080/oauth2/authorization/google» перенаправляет пользователя на страницу «accounts.google.com», где пользователь затем может приступить к выбору своего аккаунта. учетную запись Google и войдите в систему.
Он отлично работает в браузере, но я не могу найти способ сделать это с помощью flutter.
Самое большее, что мне удалось сделать, это использовать библиотека под названием "flutter_web_auth":

Код: Выделить всё

Future oauth2(String provider) async {
final String url = "http://10.0.2.2.nip.io:8080/oauth2/authorization/google";
final String result = await FlutterWebAuth.authenticate(
url: url, callbackUrlScheme: '10.0.2.2.nip:8080');
}
Однако проблема с этим подходом заключалась в том, что браузер не закрывался после аутентификации.
CallbackUrlScheme также находится в AndroidManifest.xml. (Мне нужно использовать 10.0.2.2, потому что я использую виртуальное устройство Android, а nip.io позволяет Google думать, что запрос поступает с реального сервера, поэтому это позволяет oauth).
Я был бы очень признателен за вашу помощь, и если у вас есть другие предложения, кроме flutter_web_auth, дайте мне знать.
И как мне тогда сохранить JSESSIONID?

Подробнее здесь: https://stackoverflow.com/questions/707 ... ot-backend

Вернуться в «Android»