pleio/pleio_rest

为 Pleio 应用提供的 API REST 接口。

安装量: 3,338

依赖项: 0

建议者: 0

安全性: 0

星标: 3

关注者: 2

分支: 2

公开问题: 0

类型:elgg-plugin

dev-master 2018-10-03 22:20 UTC

This package is not auto-updated.

Last update: 2024-09-15 23:05:44 UTC


README

此插件为第三方应用程序提供一个 OAuth2.0 受保护的 REST 端点,以访问 Elgg 实例。

安装

使用常规安装和激活 Elgg 插件的程序。在激活期间,插件将创建以下新表:oauth_access_tokens, oauth_authorization_codes, oauth_clients, oauth_jwt, oauth_refresh_tokens, oauth_scopes, oauth_users, elgg_push_notifications_count 和 elgg_push_notifications_subscriptions。

配置

要创建新的 OAuth2.0 客户端应用程序,在 oauth_client 表中插入一行

INSERT INTO oauth_clients ('client_id', 'client_secret', 'gcm_key', 'apns_cert') VALUES ('[my-client-id]', '[supersecret]', '[google-api-key]', '[apple-certificate-and-private-key]');

客户端_id 和客户端密钥必须在 OAuth2.0 客户端中进行配置。可选地,可以通过设置 [google-api-key] 为 Google Cloud Messaging (GCM) API 密钥,并将 [apple-certificate-and-private-key] 设置为 Apple Push 证书和私钥,来配置 iOS 和 Android 的新河对象推送通知到群组成员。要生成 Apple 证书和私钥,从您的 Apple Keychain 中导出它们,并使用以下命令

openssl x509 -in pleioapp-development.cer -inform der -out pleioapp-development.crt
openssl pkcs12 -nocerts -nodes -in pleioapp-development.p12 -out pleioapp-development.key
Enter Import Password:
MAC verified OK

cat pleioapp-development.crt pleioapp-development.key

将输出粘贴到 oauth_clients 的 apns_cert 字段中。

要接收通知,应用程序通过调用 /api/user/register_push 端点向 API 进行注册。

版本信息和文档

版本信息可在 https://[your-elgg-instance]/api 找到。要查看最新的 API 文档,请访问 https://[your-elgg-instance]/api/doc,使用 Swagger API 浏览器

重新生成 API 文档

文档由 swagger-php 自动生成。使用

composer global require zircote/swagger-php

安装此软件包。然后在插件文件夹中运行

~/.composer/vendor/bin/swagger

以生成 swagger.json。

REST 调用

通过使用 OAuth2 访问令牌进行授权。请求新的访问令牌,如下所示

curl  --data "client_id=pleioapp&client_secret=as389sfj3lkjsf3&username=admin&password=adminadmin&grant_type=password" http://www.pleio.dev/oauth/v2/token

然后执行认证请求,如下所示

curl -v -H "Authorization: Bearer <access_token>" https://www.pleio.dev/api/groups