如何使用Token认证API登录NextCloud?
- By : Will
- Category : Cloud storage
Cloud storage
1 前言
一个问题,一篇文章,一出故事。
笔者最近因为更换域名迁移用户而引发NextCloud客户端登录异常,具体表现为相同的用户名和密码登录登录到旧用户,而Web页面可以登录到正常用户。
如需了解详细操作请参阅如下连接,
因此,本章笔者熟悉NextCloud客户端的基本Token认证相关的API使用。
2 最佳实践
2.1 获取应用密码
curl -X GET \ -H "OCS-APIRequest: true" \ -H "User-Agent: curl-cmd" \ https://will:password@nextcloud.cmdschool.org/ocs/v2.php/core/getapppassword
假设返回如下数据,
<?xml version="1.0"?> <ocs> <meta> <status>ok</status> <statuscode>200</statuscode> <message>OK</message> </meta> <data> <apppassword>fQb0ICRYoz3UcTTFxcSkMMgkszgKRPVDfGZzF8jS3QrNsS78vCBR9IvUrSao0R8oHII7UIRA</apppassword> </data> </ocs>
2.2 使用base64命令转换账号和应用密码为Token
echo -n 'will:fQb0ICRYoz3UcTTFxcSkMMgkszgKRPVDfGZzF8jS3QrNsS78vCBR9IvUrSao0R8oHII7UIRA' | base64
可见如下输出,
TTA4NDc1NjpmUWIwSUNSWW96M1VjVFRGeGNTa01NZ2tzemdLUlBWRGZHWnpGOGpTM1FyTnNTNzh2 Q0JSOUl2VXJTYW8wUjhvSElJN1VJUkE=
2.3 使用Authorization标头传送Token测试认证
curl -X GET \ -H "OCS-APIRequest: true" \ -H "User-Agent: curl-cmd" \ -H "Authorization: Basic TTA4NDc1NjpmUWIwSUNSWW96M1VjVFRGeGNTa01NZ2tzemdLUlBWRGZHWnpGOGpTM1FyTnNTNzh2Q0JSOUl2VXJTYW8wUjhvSElJN1VJUkE=" \ https://nextcloud.cmdschool.org/ocs/v1.php/cloud/user
可见如下返回信息,
<?xml version="1.0"?> <ocs> <meta> <status>ok</status> <statuscode>100</statuscode> <message>OK</message> <totalitems></totalitems> <itemsperpage></itemsperpage> </meta> <data> <storageLocation>/data/nextcloud-data/will@cmdschool.org</storageLocation> <id>will@cmdschool.org</id> <lastLogin>1727252780000</lastLogin> <backend>LDAP</backend> <subadmin/> <quota> <free>5255168188416</free> <used>8858451905</used> <total>5264026640321</total> <relative>0.17</relative> <quota>-3</quota> </quota> <avatarScope>v2-federated</avatarScope> <email>will@cmdschool.org</email> <emailScope>v2-federated</emailScope> <additional_mail/> <additional_mailScope/> <displaynameScope>v2-federated</displaynameScope> <phone></phone> <phoneScope>v2-local</phoneScope> <address></address> <addressScope>v2-local</addressScope> <website></website> <websiteScope>v2-local</websiteScope> <twitter></twitter> <twitterScope>v2-local</twitterScope> <organisation></organisation> <organisationScope>v2-local</organisationScope> <role></role> <roleScope>v2-local</roleScope> <headline></headline> <headlineScope>v2-local</headlineScope> <biography></biography> <biographyScope>v2-local</biographyScope> <profile_enabled>1</profile_enabled> <profile_enabledScope>v2-local</profile_enabledScope> <groups/> <language>en</language> <locale></locale> <notify_email/> <backendCapabilities> <setDisplayName></setDisplayName> <setPassword></setPassword> </backendCapabilities> <display-name>Will</display-name> </data> </ocs>
没有评论