2017-12-18 02:22:09 +00:00
|
|
|
import { doFederatedApiCall } from "./helpers";
|
|
|
|
import { OpenId } from "../models/OpenId";
|
|
|
|
|
|
|
|
export class MatrixOpenIdClient {
|
|
|
|
|
|
|
|
constructor(private openId: OpenId) {
|
|
|
|
}
|
|
|
|
|
2018-03-24 03:26:14 +00:00
|
|
|
public async getUserId(): Promise<string> {
|
2018-03-24 23:09:34 +00:00
|
|
|
// TODO: Implement/prefer https://github.com/matrix-org/matrix-doc/issues/1115
|
|
|
|
// #1115 also means this should become a client API call, not a federated one (finally)
|
2018-03-24 03:26:14 +00:00
|
|
|
const response = await doFederatedApiCall(
|
2017-12-18 02:22:09 +00:00
|
|
|
"GET",
|
|
|
|
this.openId.matrix_server_name,
|
|
|
|
"/_matrix/federation/v1/openid/userinfo",
|
|
|
|
{access_token: this.openId.access_token}
|
2018-03-24 03:26:14 +00:00
|
|
|
);
|
|
|
|
return response['sub'];
|
2017-12-18 02:22:09 +00:00
|
|
|
}
|
|
|
|
}
|