Skip to content

Commit

Permalink
SSO completed
Browse files Browse the repository at this point in the history
  • Loading branch information
agile.zhou committed Aug 20, 2023
1 parent 7f75d61 commit 319a267
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 27 deletions.
3 changes: 2 additions & 1 deletion AgileConfig.Server.Apisite/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public async Task<IActionResult> OidcLoginByCode(string code)
Password = "/",
CreateTime = DateTime.Now,
Status = UserStatus.Normal,
Salt = ""
Salt = "",
Source = UserSource.SSO
};
await _userService.AddAsync(newUser);
}
Expand Down
3 changes: 3 additions & 0 deletions AgileConfig.Server.Apisite/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public async Task<IActionResult> Sys()
return Json(new
{
appVer,
passwordInited = await _settingService.HasSuperAdmin(),
ssoEnabled = Appsettings.SsoEnabled,
ssoButtonText = Appsettings.SsoButtonText
});
}

Expand Down
2 changes: 1 addition & 1 deletion AgileConfig.Server.Apisite/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ExpireSeconds": 86400 // 过期时间
},
"SSO": {
"enabled": true,
"enabled": false,
"loginButtonText": "SSO",
"OIDC": {
"clientId": "2bb823b7-f1ad-48c7-a9a1-713e9a885a5d",
Expand Down
4 changes: 2 additions & 2 deletions AgileConfig.Server.Apisite/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"ExpireSeconds": 86400 // 过期时间
},
"SSO": {
"enabled": true,
"loginButtonText": "SSO",
"enabled": false,
"loginButtonText": "",
"OIDC": {
"clientId": "",
"clientSecret": "",
Expand Down
12 changes: 11 additions & 1 deletion AgileConfig.Server.Data.Entity/User.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using FreeSql.DataAnnotations;
using System;
using System.Diagnostics;

namespace AgileConfig.Server.Data.Entity
{
[Table(Name = "agc_user")]
[OraclePrimaryKeyName("agc_user_pk")]
public class User
{
[Column(Name = "id", StringLength = 36)]
[Column(Name = "id", StringLength = 50)]
public string Id { get; set; }

[Column(Name= "user_name" , StringLength = 50)]
Expand All @@ -30,11 +31,20 @@ public class User

[Column(Name = "status")]
public UserStatus Status { get; set; }

[Column(Name = "source")]
public UserSource Source { get; set; }
}

public enum UserStatus
{
Normal = 0,
Deleted = -1
}

public enum UserSource
{
Normal = 0,
SSO = 1
}
}
4 changes: 3 additions & 1 deletion AgileConfig.Server.UI/react-ui-antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"analyze": "cross-env ANALYZE=1 umi build",
"build": "umi build",
"build:ssl-legacy": "set NODE_OPTIONS=--openssl-legacy-provider && umi build",
"deploy": "npm run site && npm run gh-pages",
"dev": "npm run start:dev",
"fetch:blocks": "pro fetch-blocks && npm run prettier",
Expand All @@ -20,7 +21,8 @@
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
"precommit": "lint-staged",
"prettier": "prettier -c --write \"src/**/*\"",
"start": "set NODE_OPTIONS=--openssl-legacy-provider && cross-env UMI_ENV=dev umi dev",
"start": "cross-env UMI_ENV=dev umi dev",
"start:ssl-legacy": "set NODE_OPTIONS=--openssl-legacy-provider && npm run start",
"start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev umi dev",
"start:no-mock": "cross-env MOCK=none UMI_ENV=dev umi dev",
"start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev umi dev",
Expand Down
6 changes: 3 additions & 3 deletions AgileConfig.Server.UI/react-ui-antd/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type UserModelType = {
fetchCurrent: Effect;
};
reducers: {
saveCurrentUser: Reducer<UserModelState>;
saveCurrentSystemInfo: Reducer<UserModelState>;
changeNotifyCount: Reducer<UserModelState>;
};
};
Expand Down Expand Up @@ -66,14 +66,14 @@ const UserModel: UserModelType = {
currentFunctions: currentInfo.currentUser?.currentFunctions
};
yield put({
type: 'saveCurrentUser',
type: 'saveCurrentSystemInfo',
payload: response,
});
},
},

reducers: {
saveCurrentUser(state, action) {
saveCurrentSystemInfo(state, action) {
setAuthority(action.payload.currentAuthority);
setFunctions(action.payload.currentFunctions);
setUserInfo({name:action.payload.name, userid: action.payload.userid});
Expand Down
6 changes: 5 additions & 1 deletion AgileConfig.Server.UI/react-ui-antd/src/pages/OIDC/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PageContainer } from '@ant-design/pro-layout';
import React, { useEffect, useState } from 'react';
import { Spin } from 'antd';
import styles from './index.less';
import { oidcLogin } from '@/services/login';
Expand All @@ -20,7 +21,10 @@ const logs:React.FC = (props: any) => {
id: 'pages.login.loginsuccess'
});
message.success(msg);
loginModel.reducers.changeLoginStatus({}, {payload: response});
loginModel.reducers.changeLoginStatus({}, {
payload: response,
type: 'changeLoginStatus'
});
history.replace('/');
}
else {
Expand Down
10 changes: 0 additions & 10 deletions AgileConfig.Server.UI/react-ui-antd/src/pages/OIDC/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
import request from '@/utils/request';
import { LogListParams } from './data';

export async function queryLogs(params?: LogListParams) {
console.log(params);
return request('syslog/search', {
params,
});
}

19 changes: 13 additions & 6 deletions AgileConfig.Server.UI/react-ui-antd/src/pages/User/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { history } from 'umi';
import type { StateType } from '@/models/login';
import type { LoginParamsType } from '@/services/login';
import type { ConnectState } from '@/models/connect';
import { PasswordInited } from './service'
import styles from './index.less';
import { Button } from 'antd';

Expand All @@ -19,17 +18,25 @@ export type LoginProps = {
userLogin: StateType;
submitting?: boolean;
};
import { sys } from '@/services/system';

const Login: React.FC<LoginProps> = (props) => {
const { userLogin = {}, submitting } = props;
const [type, setType] = useState<string>('account');
const { submitting } = props;
const [type] = useState<string>('account');
const [ssoEnabled, setSsoEnabled] = useState<boolean>(false);
const [ssoLoginButtonText, setSsoLoginButtonText] = useState<string>('SSO Login');
const intl = useIntl();

useEffect(()=>{
PasswordInited().then(resp=> {
if (!resp.data) {
sys().then(resp=> {
console.log(resp);
if (!resp.passwordInited) {
history.replace('/user/initpassword');
}
setSsoEnabled(resp.ssoEnabled);
if(resp.ssoButtonText) {
setSsoLoginButtonText(resp.ssoButtonText);
}
})
},[])

Expand Down Expand Up @@ -127,7 +134,7 @@ const Login: React.FC<LoginProps> = (props) => {
>
</div>
</ProForm>
<Button type="primary" size='large' style={{ width:'100%', marginTop:'20px' }} href='/oidc/login' >单点登录</Button>
<Button hidden={!ssoEnabled} type="primary" size='large' style={{ width:'100%', marginTop:'20px' }} href='/sso/login' >{ ssoLoginButtonText }</Button>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion AgileConfig.Server.UI/react-ui-antd/src/services/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function accountLogin(params: LoginParamsType) {
}

export async function oidcLogin(code: string) {
return request('admin/oidc', {
return request('admin/oidc/login', {
method: 'GET',
params: {
code: code
Expand Down

0 comments on commit 319a267

Please sign in to comment.