Merge branch 'client-enhance-implement-openid' into 'master'

[Client] Implement request openID

Closes #50

See merge request famedly/famedlysdk!160
This commit is contained in:
Christian Pauly 2020-01-12 10:34:03 +00:00
commit 62bbec0918
5 changed files with 46 additions and 0 deletions

View file

@ -29,6 +29,7 @@ export 'package:famedlysdk/src/sync/user_update.dart';
export 'package:famedlysdk/src/utils/matrix_exception.dart';
export 'package:famedlysdk/src/utils/matrix_file.dart';
export 'package:famedlysdk/src/utils/mx_content.dart';
export 'package:famedlysdk/src/utils/open_id_credentials.dart';
export 'package:famedlysdk/src/utils/profile.dart';
export 'package:famedlysdk/src/utils/push_rules.dart';
export 'package:famedlysdk/src/utils/receipt.dart';

View file

@ -30,6 +30,7 @@ import 'package:famedlysdk/src/presence.dart';
import 'package:famedlysdk/src/store_api.dart';
import 'package:famedlysdk/src/sync/user_update.dart';
import 'package:famedlysdk/src/utils/matrix_file.dart';
import 'package:famedlysdk/src/utils/open_id_credentials.dart';
import 'package:famedlysdk/src/utils/turn_server_credentials.dart';
import 'package:pedantic/pedantic.dart';
import 'room.dart';
@ -1050,4 +1051,13 @@ class Client {
rooms?.sort(sortRoomsBy);
_sortLock = false;
}
/// Gets an OpenID token object that the requester may supply to another service to verify their identity in Matrix.
/// The generated token is only valid for exchanging for user information from the federation API for OpenID.
Future<OpenIdCredentials> requestOpenIdCredentials() async {
final Map<String, dynamic> response = await jsonRequest(
type: HTTPType.GET,
action: "/client/r0/user/$userID/openid/request_token");
return OpenIdCredentials.fromJson(response);
}
}

View file

@ -0,0 +1,19 @@
class OpenIdCredentials {
String accessToken;
String tokenType;
String matrixServerName;
int expiresIn;
OpenIdCredentials(
{this.accessToken,
this.tokenType,
this.matrixServerName,
this.expiresIn});
OpenIdCredentials.fromJson(Map<String, dynamic> json) {
accessToken = json['access_token'];
tokenType = json['token_type'];
matrixServerName = json['matrix_server_name'];
expiresIn = json['expires_in'];
}
}

View file

@ -23,6 +23,7 @@
import 'dart:async';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/src/account_data.dart';
import 'package:famedlysdk/src/client.dart';
import 'package:famedlysdk/src/presence.dart';
@ -315,6 +316,14 @@ void main() {
expect(loginResp, true);
});
test('createRoom', () async {
final OpenIdCredentials openId = await matrix.requestOpenIdCredentials();
expect(openId.accessToken, "SomeT0kenHere");
expect(openId.tokenType, "Bearer");
expect(openId.matrixServerName, "example.com");
expect(openId.expiresIn, 3600);
});
test('createRoom', () async {
final List<User> users = [
User("@alice:fakeServer.notExisting"),

View file

@ -522,6 +522,13 @@ class FakeMatrixApi extends MockClient {
static final Map<String, Map<String, dynamic>> api = {
"GET": {
"/client/r0/user/@test:fakeServer.notExisting/openid/request_token":
(var req) => {
"access_token": "SomeT0kenHere",
"token_type": "Bearer",
"matrix_server_name": "example.com",
"expires_in": 3600
},
"/client/r0/rooms/1/state/m.room.member/@alice:example.com": (var req) =>
{"displayname": "Alice"},
"/client/r0/profile/@getme:example.com": (var req) => {