/// <summary> /// Gets the access token with a previously received code. /// </summary> /// <param name="client">Client.</param> /// <param name="user">User.</param> /// <param name="accessCode">Access code.</param> public void GetAccessTokenWithCode(ThirdPartyClient client, Coflnet.CoflnetUser user, string accessCode) { var request = new RestRequest(client.service.TokenPath); var restClient = new RestClient(client.service.GetUrl()); request.AddHeader("grant_type", "authorization_code"); request.AddHeader("client_id", client.id); request.AddHeader("client_secret", client.secret); request.AddHeader("code", accessCode); var response = restClient.Execute(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new CoflnetException("oauth_failed", $"Oauth handshake failed, {client.service.Slug} responded with: `{response.Content}`"); } var binary = MessagePack.MessagePackSerializer.ConvertFromJson(response.Content); var content = MessagePack.MessagePackSerializer.Deserialize <OAuthResponse>(binary); Oauth2Token token = new Oauth2Token(user, content.access_token, client.service, System.DateTime.Now.AddSeconds(content.expires_in), content.refresh_token); user.ThirdPartyTokens[client.service.Slug] = token; }
public override Entity CreateResource(CommandData data) { CreateUserRequest request = data.GetAs <CreateUserRequest> (); var user = new CoflnetUser(data.SenderId); user.PrivacySettings = request.privacySettings; return(user); }
public static CoflnetUser Generate(EntityId owner, EntityManager referenceManager = null) { var user = new CoflnetUser(owner); // generate a secret user.Secret = unity.libsodium.StreamEncryption.GetRandomBytes(16); user.AssignId(referenceManager); return(user); }
public override void Execute(CommandData data) { RegisterUserRequest request = data.GetAs <RegisterUserRequest> (); // validate captcha Token // todo :) CoflnetUser user = CoflnetUser.Generate(request.clientId, data.CoreInstance.EntityManager); user.PrivacySettings = request.privacySettings; var response = new RegisterUserResponse(); response.id = user.Id; response.secret = user.Secret; data.SendBack(CommandData.CreateCommandData <RegisteredUser, RegisterUserResponse> (data.SenderId, response)); //SendTo(data.sId, user.PublicId, "createdUser"); }
public PushNotificationToken(CoflnetUser user, string token, PushNotificationProvider provider) : base(user, token) { this.provider = provider; this.notificationIds = new List <string>(); }
public Oauth2Token(CoflnetUser user, string token, IThirdPartyApi party, DateTime expiration, string refreshToken) : base(user, token, party) { this.expiration = expiration; this.refreshToken = refreshToken; }
public ThirdPartyToken(CoflnetUser user, string token, IThirdPartyApi party) { this.user = user; this.token = token; this.party = party; }
public ThirdPartyToken(CoflnetUser user, string token) { this.user = user; this.token = token; }