SuccessFactors OData OAuth with SAP IAS-generated SAML assertion
导读
IAS:一句话说明白。SAP相关的系统可以通过IAS登录,只要IAS登录,其他系统免密登录。
作者:vivi,来源:osinnovation
上图有三个角色:brower,就是自己的浏览器,sp就是我们的目标系统,有可能是Successfactors或者其他云,idp就是ias系统。
上图大致的逻辑就是,你通过浏览器去访问sf(sp)系统(https://performancemanager15.sapsf.cn/sf/start/#/companyEntry),sf把这个请求转到idp(ias)中,ias会和sf系统做信任,所以登录ias系统,就自动跳转到sf系统。
具体可以参考:https://blog.csdn.net/weixin_33743703/article/details/92960139?ops_request_misc=&request_id=&biz_id=102&utm_term=smal%20%E5%85%AC%E9%92%A5%E4%B8%8E%E7%A7%81%E9%92%A5&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-92960139.142^v101^pc_search_result_base9&spm=1018.2226.3001.4187
理解IAS,我们先理解下上面这个图,方便以后做单点登录的朋友,特别是SuccessFactors的顾问,因为sso不是技术解决方案,应该算业务解决方案,所以这个技术要求比较高,但是不属于开发类的对sf顾问来说比较难,今天用一个例子去介绍这几个的含义
我们都知道,大企业都有很多的子系统,如果每个系统都要输入账号与密码,那这个很困难,时间长根本记不住,所以就需要通过SSO的方式,只要登录一个系统,所有系统就免密登录。
SP:SP简单理解就是我们的应用系统,例如SAP的sucessfactors、ariba、sac分析云系统。
IDP:sap有7朵云,那么这7个应用系统是不是可以通过一套系统登录,这7朵云都免密登录,这个idp就是架在7朵云之前的系统。
1.SAMLRequest
-
当用户的身份无法鉴定时,SP 会向 IdP 发送 SAML Request 信息(通过浏览器发送),请求 IdP 来鉴定用户身份。
2.SAMLResponse
-
IdP 收到 SAML Request 后,会对用户身份进行认证:当用户在 IdP 完成登录后,SAML IdP 将用户身份断言发送给 SP(放在表单中,通过浏览器 POST 请求发送)。SAML IdP 的响应内容如下:
上面是前备技能,后期会专门用springboot+saml+ias的SSO跳转的例子。
1. Background / Design
昨天分享一篇文章,是上图②的下部分操作(外部idp服务生成smal assertion),今天分析下上部分②的逻辑
如何生成smal
vivi rsl,公众号:osinnovation如果通过认证方式调用Sf的api
2. Setup
2.1.1 Retrieve the SAP IAS signing certificate
In IAS, 在租用菜单设置 (tenant settings). "Applications & Resources" and there to “Tenant Settings”. In the tenant settings, the signing certificate can be retrieved in “Single Sign-On” “SAML 2.0 Configuration” Signing Certificates.
注意:这个的509需要和sf的application保持一致
2.2 SuccessFactors
搜索栏OAuth2 Client application
Name | Value |
Company | <SAP SF company> |
Application Name | Custom application name |
Description | Custom description |
Application URL | sf地址 |
Bind to users | Optional |
x.509 certificate | successfactors产生的加密文件,里面有公钥与私钥 |
API key | 系统生成,后面需要使用 |
2.3. IAS Application
下一个步骤就是创建ias application,他会生成smal assertion,可以用用他获取successfactors的token,IAS应用程序将处理SAML和OAuth请求
2.3.1 Create an IAS SAML Application.
IAS Admin Applications & Resources Applications Create.
Name | Value |
Display name | <custom> |
Home URL | <empty> |
Type | <optional> ("custom" types might be charged) |
Parent application | None |
Protocol Type | SAML 2.0 |
2.3.2 SAML 2.0 Configuration
SAML应用程序需要使用SuccessFactors中的令牌URL进行配置。此步骤对于使应用程序能够使用“收件人”中的URL生成SAML断言至关重要。.
<select previously created application> Trust Single Sign-On SAML 2.0 Configuration.
Name | Value |
Name | <custom> |
URL for Principal Propagation | SFAPI token URL (<SF endpoint>/oauth/token) For preview (example): https://api15preview.sapsf.cn/oauth/token For production (example): https://api15.sapsf.cn/oauth/token |
2.3.3 Subject Name Identifier and Default Name ID Format
2.3.4 Attributes
删除所有默认的属性,添加api_key,value的值是sucessfactors里面设置的key
2.4 Allow Token Exchange Flow
保存以后,需要在切换到smal2.0
2.5 Applications APIs – Client Authentication
初始化创建ias access token
<select previously created application> Application APIs Client Authentication.
上面是IAS系统配置的相关参数,下面就是需要开始通过工具postmain去测试,测试分三个步骤,
步骤一:通过账号与密码的方式访问ias,得到access_token,需要在params数输入三个参数
需要在headers中输入下面两个参数
Content-Type application/x-www-form-urlencoded
Authorization:注意这里的把ClientID与ClientSecret, 按照这样的格式“Client1:Secret2"转base64,也就是下图中Basic后面生成的那串数字
输入的地址如下https://IAS/oauth2/token?grant_type=password&username=xxx&password=xxx,这IAS是ias的服务器地址,请求是post请求,
步骤二 使用上面的accen_token访问ias系统帮我们生成的saml assertion
curl --location 'https://{IAS_HOST}/oauth2/token?grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic {base64-clientid-secret}' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'subject_token={access token}' \
--data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:access_token' \
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:saml2' \
步骤三 访问sf系统获取到token
注意: 这个时候是访问sf的地址,不是iAS的地址, 比如中国就是http://api15preview.sapsf.cn,这个是开发系统,生产环境去掉preview,注意这里的Your SF API endpoint是sf的地址,company_id是sf公司名称,client_id是sf系统的api_key,就是下图中的api_key,access token就是步骤二生成的saml assertion的access_token
Example:
curl --location 'https://<Your SF API endpoint>/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'company_id=<Your Company ID>&client_id=<Your API Key>&grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=<access token>
4 最后一步,用生成的token去访问SF的odata api(因为我的odata api环境问题,在postmain中无法查看,只能通过sf 日志查看)
Example:
curl --location 'https://<Your SF API endpoint>/odata/v2/User?
--header 'Authorization: Bearer <access token>'