我正在为我的公司开发一个 flutter 应用程序。在我的公司,很多Web应用程序都使用Azure SSO和SAML连接,在站点之间切换时不需要重复登录。我想使用我开发的移动应用程序中的应用程序内 Web 浏览器直接重定向到这些网站。为此,我应该在 Azure 或 Flutter 中遵循哪些步骤和详细信息?这样的系统可能吗?
static final Config config = new Config(
tenant: "YOUR_TENANT_ID",
clientId: "YOUR_CLIENT_ID",
scope: "openid profile offline_access",
redirectUri: "your redirect url available in azure portal",
navigatorKey: navigatorKey,
webUseRedirect: true,
loader: Center(child: CircularProgressIndicator()),
postLogoutRedirectUri: 'http://your_base_url/logout', //optional
);
final AadOAuth oauth = new AadOAuth(config);
final result = await oauth.login();
此代码使用aad_oauth 库。我登录并收到访问令牌,但无法访问具有相同登录方法的机构附属网站。有时它会返回 401 UNAUTHORIZED 错误,有时会重定向回登录页面。
尝试这个新包,它使用默认的应用程序内浏览器登录,这些应用程序内浏览器通常会保存令牌,当您打开公司的其他网站时,它们可能会像您要求的那样直接登录。但没有承诺。
您只需要知道您的
tenant id, client id and the port
在重定向 URI(通常是 http://localhost:3000)中添加到 Azure 应用程序注册。
class AuthenticationHandler {
static final AuthenticationHandler _instance =
AuthenticationHandler._internal();
factory AuthenticationHandler() {
return _instance;
}
AuthenticationHandler._internal();
final AzureAuth _microsoftAuthenticator = AzureAuth(
authenticatorProvider: DefaultAuthenticator(
'https://login.microsoftonline.com/{tenant-id}/',
["openId", "offline_access"],
'{client-id}',
'&prompt=select_account',
3000, // localhost redirect uri port
),
);
Future<void> login() async {
await _microsoftAuthenticator.login();
}
Future<void> silentLogin() async {
await _microsoftAuthenticator.silentLogin();
}
Future<void> logout() async {
await _microsoftAuthenticator.logout();
}
}
如果您需要更多详细信息,请参阅此完整示例。 azure_silent_auth