A method carried out by a first device supporting a neighbor awareness network, NAN, based on NAN sync beacons, for configuring a connection with a second device, the second device providing access to a network of a communication system, the method comprising: discovering the second device supporting a NAN and located within a predetermined range from the first device; generating an ephemeral key, P E, of the first device based on a unique identity value of the first device and a random value, Nonce E; transmitting, to the second device, a NAN service discovery frame, SDF, subscribe message for subscribing to the second device, the NAN SDF subscribe message including the ephemeral key P E of the first device for identifying the first device and the random value Nonce E wherein the ephemeral key P E is determined by the first device based on the equation P E = Nonce E *P I, wherein P I is a unique identity key of the first device; receiving, from the second device, a NAN SDF publish message, the NAN SDF publish message includes an ephemeral key P E of the second device for identifying the second device and information indicating that the access to the network can be provided, wherein the ephemeral key P E of the second device is determined by the second device based on the equation P E = Nonce E *P I, wherein P I is a unique identity value of the second device and the random value (Nonce E) is extracted from the NAN SDF subscribe message; creating a shared secret key and transmitting, to the second device, a NAN SDF follow-up message indicating that a subscription to the second device has been confirmed and that the shared secret key has been created; receiving, from the second device, the NAN SDF follow-up message including configuration data, the configuration data being encrypted by the shared secret key; cancelling the subscription to the second device; and performing discovery with the second device through one channel scan and establishing a secure connection between the first device and the second device based on the encrypted configuration data. discovering the second device supporting a NAN and located within a predetermined range from the first device; generating an ephemeral key, P E, of the first device based on a unique identity value of the first device and a random value, Nonce E; transmitting, to the second device, a NAN service discovery frame, SDF, subscribe message for subscribing to the second device, the NAN SDF subscribe message including the ephemeral key P E of the first device for identifying the first device and the random value Nonce E wherein the ephemeral key P E is determined by the first device based on the equation P E = Nonce E *P I, wherein P I is a unique identity key of the first device; receiving, from the second device, a NAN SDF publish message, the NAN SDF publish message includes an ephemeral key P E of the second device for identifying the second device and information indicating that the access to the network can be provided, wherein the ephemeral key P E of the second device is determined by the second device based on the equation P E = Nonce E *P I, wherein P I is a unique identity value of the second device and the random value (Nonce E) is extracted from the NAN SDF subscribe message; creating a shared secret key and transmitting, to the second device, a NAN SDF follow-up message indicating that a subscription to the second device has been confirmed and that the shared secret key has been created; receiving, from the second device, the NAN SDF follow-up message including configuration data, the configuration data being encrypted by the shared secret key; cancelling the subscription to the second device; and performing discovery with the second device through one channel scan and establishing a secure connection between the first device and the second device based on the encrypted configuration data.