-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add external api #54
base: main
Are you sure you want to change the base?
Add external api #54
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dart:convert'; | ||
import 'package:sky/native_interaction/rubix/rubix_util.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
|
||
Future<bool> fireAuthCallback({required String did,required String peerId,required String callBackUrl,required Token orgAccessToken,required String sessionId,required String chain })async { | ||
var bodyJsonStr = jsonEncode({ | ||
'did': '$did.$peerId', | ||
'session_id': sessionId, | ||
'token': orgAccessToken.token, | ||
'chain': chain, | ||
}); | ||
try{ | ||
var response = await http.post( | ||
Uri.parse(callBackUrl), | ||
headers: <String, String>{ | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}, | ||
body: bodyJsonStr, | ||
); | ||
if (response.statusCode == 200) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}catch(e, s){ | ||
print(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. print stack trace too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
print(s); | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ final String _secret = Config().jwtAuthSecret; | |
final String _issuer = 'Fexr Sky'; | ||
final String _portMapIndex = 'peer_id_index'; | ||
|
||
enum _RubixTokenType { challengeToken, accessToken, externalAccessToken } | ||
enum _RubixTokenType { challengeToken, accessToken, externalAccessToken, orgAccessToken } | ||
|
||
String _getClaimType(JwtClaim claim) { | ||
return claim.toJson()['type']; | ||
|
@@ -263,6 +263,65 @@ class ExternalAccessTokenJWTClaim extends JwtClaim { | |
} | ||
} | ||
|
||
class OrgAccessTokenJWTClaim extends JwtClaim { | ||
OrgAccessTokenJWTClaim({ | ||
required String did, | ||
required DateTime expiry, | ||
required String peerId, | ||
required String orgName, | ||
}) : super( | ||
issuer: _issuer, | ||
subject: orgName, | ||
maxAge: Duration(days: 30), | ||
otherClaims: { | ||
'type': _RubixTokenType.orgAccessToken.toString(), | ||
'peerId': peerId, | ||
'did': did, | ||
}, | ||
); | ||
|
||
factory OrgAccessTokenJWTClaim.fromJWTClaim(JwtClaim claim) { | ||
return OrgAccessTokenJWTClaim( | ||
orgName: claim.subject!, | ||
expiry: claim.expiry!, | ||
peerId: claim.toJson()['peerId'], | ||
did: claim.toJson()['did'], | ||
); | ||
} | ||
|
||
factory OrgAccessTokenJWTClaim.fromToken(String token) { | ||
return OrgAccessTokenJWTClaim.fromJWTClaim( | ||
verifyJwtHS256Signature(token, _secret)); | ||
} | ||
|
||
String getOrgName() { | ||
return subject!; | ||
} | ||
|
||
String getPeerId() { | ||
return toJson()['peerId']; | ||
} | ||
|
||
String getDID() { | ||
return toJson()['did']; | ||
} | ||
} | ||
|
||
class OrgAccessToken { | ||
static final int _accessTokenMaxAge = 30; // days | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. token age might be something we have to worry about but not during a poc. We need to come back on this. |
||
static Token get( | ||
{required String did, required String peerId, required String orgName}) { | ||
final JwtClaim claimSet = OrgAccessTokenJWTClaim( | ||
did: did, | ||
expiry: DateTime.now().add(Duration(days: _accessTokenMaxAge)), | ||
peerId: peerId, | ||
orgName: orgName, | ||
); | ||
|
||
return Token(issueJwtHS256(claimSet, _secret), claimSet.expiry!); | ||
} | ||
} | ||
|
||
class ExternalAccessToken { | ||
static final int _accessTokenMaxAge = 30; // days | ||
static Token get( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must have been coming from phone,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, no, not need as this is rubix ext rpc. But could have simply passed this to the next function without having to store it in a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will make that change.