Exemple #1
0
    /// <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;
    }
Exemple #2
0
        public override Entity CreateResource(CommandData data)
        {
            CreateUserRequest request = data.GetAs <CreateUserRequest> ();
            var user = new CoflnetUser(data.SenderId);

            user.PrivacySettings = request.privacySettings;
            return(user);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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");
        }
Exemple #5
0
 public PushNotificationToken(CoflnetUser user, string token, PushNotificationProvider provider) : base(user, token)
 {
     this.provider        = provider;
     this.notificationIds = new List <string>();
 }
Exemple #6
0
 public Oauth2Token(CoflnetUser user, string token, IThirdPartyApi party, DateTime expiration, string refreshToken) : base(user, token, party)
 {
     this.expiration   = expiration;
     this.refreshToken = refreshToken;
 }
Exemple #7
0
 public ThirdPartyToken(CoflnetUser user, string token, IThirdPartyApi party)
 {
     this.user  = user;
     this.token = token;
     this.party = party;
 }
Exemple #8
0
 public ThirdPartyToken(CoflnetUser user, string token)
 {
     this.user  = user;
     this.token = token;
 }