セキュリティキーの取得

セキュリティキーの取得

- max email の投稿
返信数: 4
私のホームページからmoodleをAPIによってバックエンドで利用したいと考えております。

その際に、ユーザーの登録毎にトークンを手動発行するのは非効率であったため、moodle/webservice:createtokenをオンにしてセキュリティーキーをユーザー毎に発行するようにしました。

しかし、APIを利用するのにセキュリティーキーを毎回コピーして手動でphpファイルに書き込むのは無理があるので、セキュリティーキーをどうにか取得・保存できる方法はないか模索している次第であります。

お手数ですが、解決方法をご教示いただけませんでしょうか。

(追記)
現在、Google Oauth認証を利用しておりますが、GoogleOauth認証で難しいようでしたら他のログイン方法での取得方法をご教示いただけますと幸いです。
max email への返信

Re: セキュリティキーの取得

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

すでにご覧になったかもしれませんが、以下のページが参考になるのではないでしょうか。

[Login token - MoodleDocs]
https://docs.moodle.org/dev/Login_token

[OAuth 2 API - MoodleDocs]
https://docs.moodle.org/dev/OAuth_2_API

[Moodle plugins directory: User key authentication]
https://moodle.org/plugins/auth_userkey

Mitsuhiro Yoshida への返信

Re: セキュリティキーの取得

- max email の投稿
yoshida様

参考リンク送っていただき有難うございます。
非常に参考になりました。
ログイン中のユーザーのユーザーID取得(クラス設計)に関して、詳しい情報などございませんでしょうか。

お忙しい所恐縮ですが、よろしくお願い致します。
max email への返信

Re: セキュリティキーの取得

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

Moodle 3.11+ (Build: 20210527) でしたら、lib/setup.phpの453行目あたりの以下の記述が参考になるかと思います。

/**
 * Holds the user table record for the current user. Will be the 'guest'
 * user record for people who are not logged in.
 *
 * $USER is stored in the session.
 *
 * Items found in the user record:
 *  - $USER->email - The user's email address.
 *  - $USER->id - The unique integer identified of this user in the 'user' table.
 *  - $USER->email - The user's email address.
 *  - $USER->firstname - The user's first name.
 *  - $USER->lastname - The user's last name.
 *  - $USER->username - The user's login username.
 *  - $USER->secret - The user's ?.
 *  - $USER->lang - The user's language choice.
 *
 * @global object $USER
 * @name $USER
 */
global $USER;